Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.
private static double GetArea(PointF[] points) {
SqlGeographyBuilder builder = new SqlGeographyBuilder();
builder.SetSrid(4326); // 4326 is Spatial Reference Identifier for WGS84
builder.BeginGeography(OpenGisGeographyType.Polygon);
// Construct the Polygon from all the points
builder.BeginFigure(points[0].Y, points[0].X);
for (int i = 1; i < points.Length;i++){
builder.AddLine(points[i].Y, points[i].X);
}
// Polygon's Start point must be equal to the end point
if (points[0] != points[points.Length-1])
builder.AddLine(points[0].Y, points[0].X);
builder.EndFigure();
builder.EndGeography();
// Return the area
return builder.ConstructedGeography.STArea().Value;
}
// Microsoft.SqlServer.Types
double[] latitudes = { -33, -31, -30, -33 };
double[] longitudes = { 151, 152, 152, 151 };
SqlGeographyBuilder gb = new SqlGeographyBuilder();
gb.SetSrid(4326); // set spatial reference to WGS84
gb.BeginGeography(OpenGisGeographyType.Polygon);
gb.BeginFigure(latitudes[0], longitudes[0]); // start point
for (int i = 1; i < latitudes.Length; i++)
gb.AddLine(latitudes[i], longitudes[i]);
gb.EndFigure();
gb.EndGeography();
SqlGeography g = gb.ConstructedGeography;
double squareMeters = g.STArea().Value;
double squareAcres = squareMeters * 0.000247105381;
public static bool Test() {
SurveySegment[] segs = new SurveySegment[]{
new SurveySegment(){Degrees=06, Minutes=27, Seconds=11, Length=488.27, IsSouth=false, IsWest=false},
new SurveySegment(){Degrees=07, Minutes=01, Seconds=06, Length=347.57, IsSouth=false, IsWest=true},
new SurveySegment(){Degrees=76, Minutes=50, Seconds=13, Length=447.76, IsSouth=false, IsWest=false},
new SurveySegment(){Degrees=03, Minutes=47, Seconds=57, Length=205.31, IsSouth=true, IsWest=false},
new SurveySegment(){Degrees=03, Minutes=14, Seconds=01, Length=224.48, IsSouth=true, IsWest=false},
new SurveySegment(){Degrees=02, Minutes=58, Seconds=30, Length=111.00, IsSouth=true, IsWest=false},
new SurveySegment(){Degrees=77, Minutes=18, Seconds=15, Length=129.23, IsSouth=false, IsWest=true},
new SurveySegment(){Degrees=14, Minutes=55, Seconds=04, Length=519.65, IsSouth=true, IsWest=true},
new SurveySegment(){Degrees=69, Minutes=10, Seconds=01, Length=232.85, IsSouth=false, IsWest=true}
};
double area = GetArea(segs);
}
private static double GetArea(SurveySegment[] segments) {
SqlGeometryBuilder builder = new SqlGeometryBuilder();
builder.SetSrid(0); // Don't need an SRID here
builder.BeginGeometry(OpenGisGeometryType.Polygon);
// Walk around the segments
PointF p = new PointF(0, 0);
builder.BeginFigure(p.X, p.Y);
for (int i = 0; i < segments.Length; i++) {
p += segments[i].FromOrigin;
builder.AddLine(p.X, p.Y);
}
// Polygon's end point must be at the origin
if (p.X != 0 || p.Y != 0)
builder.AddLine(0, 0);
builder.EndFigure();
builder.EndGeometry();
// Return the area in the units used in the segments
return builder.ConstructedGeometry.STArea().Value;
}
public struct SurveySegment {
public byte Degrees, Minutes, Seconds;
public bool IsSouth, IsWest;
public double Length;
public double DecimalDegrees {
get {
double angle = Degrees + ((double)Minutes / 60) + ((double)Seconds / 3600);
if (IsSouth) {
// If to the East & looking South, the angle is negative
if (!IsWest) angle *= -1;
// If looking South, add 180°
angle += 180;
} else {
// If to the West & looking North, the angle is negative
if (IsWest) angle *= -1;
}
// Only use positive angles (0° <= angle < 360°)
return (angle + 360) % 360;
}
}
public SizeF FromOrigin {
get {
/* The Y value is inverted so this can be rendered straight
* to a GDI object.
* ie. Left (East) is positive, Down (South) is positive
*/
double angle = DecimalDegrees * Math.PI / 180;
return new SizeF(
(float)(Length * Math.Sin(angle)),
-(float)(Length * Math.Cos(angle))
);
}
}
}
SqlGeometry geom = GetArea(...);
double area = geom.STArea().Value;
PointF[] points = new PointF[geom.STNumPoints()];
for (int i = 0; i < points.Length; i++){
SqlGeometry g = geom.STPointN(i + 1);
points[i] = new PointF(g.STX, g.STY);
}
Bitmap bmp = new Bitmap(1000,1000);
Graphics g = Graphics.FromImage(g);
g.DrawPolygon(Pens.Black, points);
private void Foo(){
SqlGeometry geom = GetGeometry(segs);
double area = geom.STArea().Value;
Image img = GetImage(geom, "ft");
}
public static Image GetImage(SqlGeometry geom, string units) {
float minX = float.MaxValue;
float maxX = float.MinValue;
float minY = float.MaxValue;
float maxY = float.MinValue;
// Populate the points in the array
PointF[] ps = new PointF[geom.STNumPoints().Value];
for (int i = 0; i < ps.Length; i++) {
SqlGeometry temp = geom.STPointN(i + 1);
// Create the point in the array
float x = (float)temp.STX.Value;
float y = (float)temp.STY.Value;
ps[i] = new PointF(x, y);
// Get the bounds
if (x < minX) minX = x;
if (x > maxX) maxX = x;
if (y < minY) minY = y;
if (y > maxY) maxY = y;
}
// Create the bitmap to contain the bounds
// Also use a 10px border
int border = 10;
Bitmap bmp = new Bitmap(
(2 * border) + Convert.ToInt32(maxX - minX),
(2 * border) + Convert.ToInt32(maxY - minY));
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.White);
// Offset the points so that they fit on the image
Matrix transform = new Matrix();
transform.Translate(-minX + border, -minY + border);
transform.TransformPoints(ps);
// Draw the points
g.DrawPolygon(new Pen(Color.Black, 2), ps);
// Annotate the info on the centroid
SqlGeometry centroid = geom.STCentroid();
PointF[] cs = new PointF[] {
new PointF((float)centroid.STX.Value, (float)centroid.STY.Value)
};
transform.TransformPoints(cs);
Font font = new Font("Arial", 10, FontStyle.Regular);
g.DrawString(
string.Format("Area: {0:N0}{2}²\nPerimeter: {1:N0}{2}", geom.STArea().Value, geom.STLength().Value, units),
font, Brushes.Black, cs[0]);
// Tidy up & return the image
g.Dispose();
return bmp;
}
public static void DoWork() {
SurveySegment[] segs = new SurveySegment[]{
new SurveySegment(){Degrees=06, Minutes=27, Seconds=11, Length=488.27, IsSouth=false, IsWest=false},
new SurveySegment(){Degrees=07, Minutes=01, Seconds=06, Length=347.57, IsSouth=false, IsWest=true},
new SurveySegment(){Degrees=76, Minutes=50, Seconds=13, Length=447.76, IsSouth=false, IsWest=false},
new SurveySegment(){Degrees=03, Minutes=47, Seconds=57, Length=205.31, IsSouth=true, IsWest=false},
new SurveySegment(){Degrees=03, Minutes=14, Seconds=01, Length=224.48, IsSouth=true, IsWest=false},
new SurveySegment(){Degrees=02, Minutes=58, Seconds=30, Length=111.00, IsSouth=true, IsWest=false},
new SurveySegment(){Degrees=77, Minutes=18, Seconds=15, Length=129.23, IsSouth=false, IsWest=true},
new SurveySegment(){Degrees=14, Minutes=55, Seconds=04, Length=519.65, IsSouth=true, IsWest=true},
new SurveySegment(){Degrees=69, Minutes=10, Seconds=01, Length=232.85, IsSouth=false, IsWest=true}
};
SqlGeometry geom = GetGeometry(segs);
double area = geom.STArea().Value;
Image img = GetImage(geom, "ft");
img.Save(@"c:\foo.png", System.Drawing.Imaging.ImageFormat.Png);
}
private static SqlGeometry GetGeometry(SurveySegment[] segments) {
SqlGeometryBuilder builder = new SqlGeometryBuilder();
builder.SetSrid(0); // Don't need an SRID here
builder.BeginGeometry(OpenGisGeometryType.Polygon);
// Walk around the segments
PointF p = new PointF(0, 0);
builder.BeginFigure(p.X, p.Y);
for (int i = 0; i < segments.Length; i++) {
p += segments[i].FromOrigin;
builder.AddLine(p.X, p.Y);
}
// Polygon's end point must be at the origin
if (p.X != 0 || p.Y != 0)
builder.AddLine(0, 0);
builder.EndFigure();
builder.EndGeometry();
// Return Geometry
return builder.ConstructedGeometry;
}
public static Image GetImage(SqlGeometry geom, string units) {
float minX = float.MaxValue;
float maxX = float.MinValue;
float minY = float.MaxValue;
float maxY = float.MinValue;
// Populate the points in the array
PointF[] ps = new PointF[geom.STNumPoints().Value];
for (int i = 0; i < ps.Length; i++) {
SqlGeometry temp = geom.STPointN(i + 1);
// Create the point in the array
float x = (float)temp.STX.Value;
float y = (float)temp.STY.Value;
ps[i] = new PointF(x, y);
// Get the bounds
if (x < minX) minX = x;
if (x > maxX) maxX = x;
if (y < minY) minY = y;
if (y > maxY) maxY = y;
}
// Create the bitmap to contain the bounds
// Also use a 10px border
int border = 10;
Bitmap bmp = new Bitmap(
(2 * border) + Convert.ToInt32(maxX - minX),
(2 * border) + Convert.ToInt32(maxY - minY));
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.White);
// Offset the points so that they fit on the image
Matrix transform = new Matrix();
transform.Translate(-minX + border, -minY + border);
transform.TransformPoints(ps);
// Draw the points
g.DrawPolygon(new Pen(Color.Black, 2), ps);
// Annotate the info on the centroid
SqlGeometry centroid = geom.STCentroid();
PointF[] cs = new PointF[] {
new PointF((float)centroid.STX.Value, (float)centroid.STY.Value)
};
transform.TransformPoints(cs);
Font font = new Font("Arial", 10, FontStyle.Regular);
g.DrawString(
string.Format("Area: {0:N0}{2}²\nPerimeter: {1:N0}{2}", geom.STArea().Value, geom.STLength().Value, units),
font, Brushes.Black, cs[0]);
// Tidy up & return the image
g.Dispose();
return bmp;
}
public struct SurveySegment {
public byte Degrees, Minutes, Seconds;
public bool IsSouth, IsWest;
public double Length;
public double DecimalDegrees {
get {
double angle = Degrees + ((double)Minutes / 60) + ((double)Seconds / 3600);
if (IsSouth) {
// If to the East & looking South, the angle is negative
if (!IsWest) angle *= -1;
// If looking South, add 180°
angle += 180;
} else {
// If to the West & looking North, the angle is negative
if (IsWest) angle *= -1;
}
// Only use positive angles (0° <= angle < 360°)
return (angle + 360) % 360;
}
}
public SizeF FromOrigin {
get {
/* The Y value is inverted so this can be rendered straight
* to a GDI object.
* ie. Left (East) is positive, Down (South) is positive
*/
double angle = DecimalDegrees * Math.PI / 180;
return new SizeF(
(float)(Length * Math.Sin(angle)),
-(float)(Length * Math.Cos(angle))
);
}
}
}
foo.png
http://www.microsoft.com/downloads/details.aspx?familyid=B33D2C78-1059-4CE2-B80D-2343C099BCB4&displaylang=en
You could use the Microsoft.SqlServer.Types.