public void Multipg() { var rnd = new Random(); var pg = new Polygon[50]; var pgcheck = new GeoAPI.Geometries.IPolygon[50]; var gf = new NetTopologySuite.Geometries.GeometryFactory(); for (var i = 0; i < 50; i++) { var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var coord = new Coordinate[36]; var coordscheck = new GeoAPI.Geometries.Coordinate[36]; for (var ii = 0; ii < 36; ii++) { coord[ii] = new Coordinate(center.X + Math.Cos((ii * 10) * Math.PI / 10), center.Y + (ii * 10) * Math.PI / 10); var x = coord[ii].X; var y = coord[ii].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordscheck[ii] = c; } coord[35] = new Coordinate(coord[0].X, coord[0].Y); coordscheck[35] = new GeoAPI.Geometries.Coordinate(coordscheck[0].X, coordscheck[0].Y); var ring = gf.CreateLinearRing(coordscheck); pgcheck[i] = gf.CreatePolygon(ring, null); pg[i] = new Polygon(coord); } var mpg = new MultiPolygon(pg); var mpgcheck = gf.CreateMultiPolygon(pgcheck); for (var ii = 0; ii < mpg.Coordinates.Count; ii++) { Assert.AreEqual(mpg.Coordinates[ii].X, mpgcheck.Coordinates[ii].X); Assert.AreEqual(mpg.Coordinates[ii].Y, mpgcheck.Coordinates[ii].Y); } }
/// <summary> /// Gets a feature collection with features representing the stop links. /// </summary> /// <returns></returns> public static FeatureCollection GetStopLinks(this MultimodalDb db, Profile profile, uint stopId) { var features = new FeatureCollection(); var stopEnumerator = db.TransitDb.GetStopsEnumerator(); if (stopEnumerator.MoveTo(stopId)) { var stopLocation = new GeoAPI.Geometries.Coordinate(stopEnumerator.Longitude, stopEnumerator.Latitude); var attributes = new AttributesTable(); attributes.AddAttribute("stop_id", stopId); features.Add(new Feature(new Point(stopLocation), attributes)); var stopLinksDb = db.GetStopLinksDb(profile).GetEnumerator(); stopLinksDb.MoveTo(stopId); while (stopLinksDb.MoveNext()) { var routerPoint = new RouterPoint(0, 0, stopLinksDb.EdgeId, stopLinksDb.Offset); var linkLocation = routerPoint.LocationOnNetwork(db.RouterDb).ToCoordinate(); attributes = new AttributesTable(); attributes.AddAttribute("edge_id", stopLinksDb.EdgeId.ToInvariantString()); attributes.AddAttribute("offset", stopLinksDb.Offset.ToInvariantString()); features.Add(new Feature(new Point(linkLocation), attributes)); features.Add(new Feature(new LineString(new GeoAPI.Geometries.Coordinate[] { stopLocation, linkLocation }), new AttributesTable())); } } return(features); }
public void MetersDistanceTaguaTest() { var brasiliaUtmZone = 23; var originCoordinateSystem = GeographicCoordinateSystem.WGS84; var targetCoordinateSystem = ProjectedCoordinateSystem.WGS84_UTM(brasiliaUtmZone, false); var transform = new CoordinateTransformationFactory().CreateFromCoordinateSystems( originCoordinateSystem, targetCoordinateSystem); var catolica = new GeoAPI.Geometries.Coordinate(-15.8674807, -48.0310518); var taguatingaCentro = new GeoAPI.Geometries.Coordinate(-15.8326894, -48.0547287); var taguaCenter = new GeoAPI.Geometries.Coordinate(-15.8026851, -48.0685222); var catolicaCoordinate = new GeoAPI.Geometries.Coordinate(catolica.X, catolica.Y); var taguatingaCentroCoordinate = new GeoAPI.Geometries.Coordinate(taguatingaCentro.X, taguatingaCentro.Y); var taguaCenterCoordinate = new GeoAPI.Geometries.Coordinate(taguaCenter.X, taguaCenter.Y); var newcatolicaPoint = transform.MathTransform.Transform(catolicaCoordinate); var newTaguatingaCentroPoint = transform.MathTransform.Transform(taguatingaCentroCoordinate); var newTaguaCenterPoint = transform.MathTransform.Transform(taguaCenterCoordinate); var distanceTaguatingaCentro = newcatolicaPoint.Distance(newTaguatingaCentroPoint); var distanceTaguaCenter = newcatolicaPoint.Distance(newTaguaCenterPoint); distanceTaguaCenter.ShouldBeGreaterThan(distanceTaguatingaCentro); //try in strait line, at least this works }
public void PolygonCentroid() { var coords = new Coordinate[20]; var rnd = new Random(); var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var coordscheck = new GeoAPI.Geometries.Coordinate[20]; for (var i = 0; i < 19; i++) { coords[i] = new Coordinate(center.X + Math.Cos((i * 10) * Math.PI / 10), center.Y + (i * 10) * Math.PI / 10); var x = coords[i].X; var y = coords[i].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordscheck[i] = c; } coordscheck[19] = new GeoAPI.Geometries.Coordinate(coords[0].X, coords[0].Y); coords[19] = new Coordinate(coords[0].X, coords[0].Y); var gf = new NetTopologySuite.Geometries.GeometryFactory(); var ring = gf.CreateLinearRing(coordscheck); var polygonCheck = gf.CreatePolygon(ring, null); var pg = new Polygon(coords); var x1 = pg.Centroid.X; var x2 = polygonCheck.Centroid.X; AssertExt.AreEqual15(x1, x2); var y1 = pg.Centroid.Y; var y2 = polygonCheck.Centroid.Y; AssertExt.AreEqual15(y1, y2); }
public GeoAPI.Geometries.IPolygon GetPolygon() { GeoAPI.Geometries.Coordinate[] coords; if (this.Points.Count >= 3) { coords = new GeoAPI.Geometries.Coordinate[this.Points.Count + 1]; int i = 0; foreach (Point pt in this.Points) { coords[i] = new GeoAPI.Geometries.Coordinate(pt.X, pt.Y); i++; } coords[i] = new GeoAPI.Geometries.Coordinate(this.Points[0].X, this.Points[0].Y); } else { coords = new GeoAPI.Geometries.Coordinate[4]; coords[0] = new GeoAPI.Geometries.Coordinate(this.Points[0].X, this.Points[0].Y); coords[1] = new GeoAPI.Geometries.Coordinate(this.Points[0].X + 1, this.Points[0].Y); coords[2] = new GeoAPI.Geometries.Coordinate(this.Points[0].X + 1, this.Points[0].Y + 1); coords[3] = new GeoAPI.Geometries.Coordinate(this.Points[0].X, this.Points[0].Y); } return(new NetTopologySuite.Geometries.Polygon(new NetTopologySuite.Geometries.LinearRing(coords))); }
public void EnveloptMls() { var rnd = new Random(); var ls = new LineString[40]; var lscheck = new GeoAPI.Geometries.ILineString[40]; var gf = new NetTopologySuite.Geometries.GeometryFactory(); for (var ii = 0; ii < 40; ii++) { var coord = new Coordinate[36]; var coordcheck = new GeoAPI.Geometries.Coordinate[36]; for (var i = 0; i < 36; i++) { coord[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var x = coord[i].X; var y = coord[i].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordcheck[i] = c; } ls[ii] = new LineString(coord); lscheck[ii] = gf.CreateLineString(coordcheck); } var mls = new MultiLineString(ls); var mlscheck = gf.CreateMultiLineString(lscheck); Assert.AreEqual(mls.Envelope.Width, mlscheck.EnvelopeInternal.Width); Assert.AreEqual(mls.Envelope.Height, mlscheck.EnvelopeInternal.Height); }
public override GeoAPI.Geometries.Coordinate Project(double x, double y, GeoAPI.Geometries.Coordinate dst) { dst.Y = 2.0 * Math.Atan(K * Math.Pow(Math.Tan(0.5 * y + ProjectionMath.PiFourth), C) * srat(_e * Math.Sin(y), ratexp)) - ProjectionMath.PiHalf; dst.X = C * x; return(dst); }
public void Multils() { var rnd = new Random(); var ls = new LineString[40]; var lscheck = new GeoAPI.Geometries.ILineString[40]; var gf = new NetTopologySuite.Geometries.GeometryFactory(); for (var ii = 0; ii < 40; ii++) { var coord = new Coordinate[36]; var coordcheck = new GeoAPI.Geometries.Coordinate[36]; for (var i = 0; i < 36; i++) { coord[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var x = coord[i].X; var y = coord[i].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordcheck[i] = c; } ls[ii] = new LineString(coord); lscheck[ii] = gf.CreateLineString(coordcheck); } var mls = new MultiLineString(ls); var mlscheck = gf.CreateMultiLineString(lscheck); for (var ii = 0; ii < mls.Coordinates.Count; ii++) { Assert.AreEqual(mls.Coordinates[ii].X, mlscheck.Coordinates[ii].X); Assert.AreEqual(mls.Coordinates[ii].Y, mlscheck.Coordinates[ii].Y); } Assert.AreEqual(mls.NumGeometries, mlscheck.NumGeometries); }
public void OnMouseUp(GeoAPI.Geometries.Coordinate worldPosition, System.Windows.Forms.MouseEventArgs e) { if (enabled) { MessageBox.Show("Hallo Rob", "Demo MapTool"); } }
public static GeoAPI.Geometries.IPolygon GetPolygon(this IEnumerable <Point> s) { GeoAPI.Geometries.Coordinate[] coords; if (s.Count() > 3) { coords = new GeoAPI.Geometries.Coordinate[s.Count() + 1]; int i = 0; foreach (Point pt in s) { coords[i] = new GeoAPI.Geometries.Coordinate(pt.X, pt.Y); i++; } coords[i] = new GeoAPI.Geometries.Coordinate(s.First().X, s.First().Y); } else { coords = new GeoAPI.Geometries.Coordinate[5]; coords[0] = new GeoAPI.Geometries.Coordinate(s.First().X, s.First().Y); coords[1] = new GeoAPI.Geometries.Coordinate(s.First().X + 1, s.First().Y); coords[2] = new GeoAPI.Geometries.Coordinate(s.First().X + 1, s.First().Y + 1); coords[3] = new GeoAPI.Geometries.Coordinate(s.First().X, s.First().Y + 1); coords[4] = new GeoAPI.Geometries.Coordinate(s.First().X, s.First().Y); } return(new NetTopologySuite.Geometries.Polygon(new NetTopologySuite.Geometries.LinearRing(coords))); }
public override GeoAPI.Geometries.Coordinate ProjectInverse(double x, double y, GeoAPI.Geometries.Coordinate dst) { var lon = x / C; var lat = y; var num = Math.Pow(Math.Tan(0.5 * lat + ProjectionMath.PiFourth) / K, 1.0 / C); int i; for (i = MAX_ITER; i > 0; --i) { lat = 2.0 * Math.Atan(num * srat(_e * Math.Sin(y), -0.5 * _e)) - ProjectionMath.PiHalf; if (Math.Abs(lat - y) < DEL_TOL) { break; } y = lat; } /* convergence failed */ if (i <= 0) { throw new ProjectionException(this, Resources.Error.Err_17); } dst.X = lon; dst.Y = lat; return(dst); }
public void PolygonEnvelopeArea() { var coords = new Coordinate[20]; var rnd = new Random(); var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var coordscheck = new GeoAPI.Geometries.Coordinate[20]; for (var i = 0; i < 19; i++) { coords[i] = new Coordinate(center.X + Math.Cos((i * 10) * Math.PI / 10), center.Y + (i * 10) * Math.PI / 10); var x = coords[i].X; var y = coords[i].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordscheck[i] = c; } coordscheck[19] = new GeoAPI.Geometries.Coordinate(coords[0].X, coords[0].Y); coords[19] = new Coordinate(coords[0].X, coords[0].Y); var gf = new NetTopologySuite.Geometries.GeometryFactory(); GeoAPI.Geometries.ILinearRing ring = gf.CreateLinearRing(coordscheck); GeoAPI.Geometries.IPolygon pgcheck = gf.CreatePolygon(ring, null); var pg = new Polygon(coords); var area = pg.Envelope.Area(); AssertExt.AreEqual15(area, pgcheck.Envelope.Area); }
public void Overlaps() { var rnd = new Random(); var pg = new Polygon[50]; var pgcheck = new GeoAPI.Geometries.IPolygon[50]; var gf = new NetTopologySuite.Geometries.GeometryFactory(); var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); for (var i = 0; i < 50; i++) { var coord = new Coordinate[36]; var coordscheck = new GeoAPI.Geometries.Coordinate[36]; for (var ii = 0; ii < 36; ii++) { coord[ii] = new Coordinate(center.X + Math.Cos((ii * 10) * Math.PI / 10), center.Y + (ii * 10) * Math.PI / 10); var x = coord[ii].X; var y = coord[ii].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordscheck[ii] = c; } coord[35] = new Coordinate(coord[0].X, coord[0].Y); coordscheck[35] = new GeoAPI.Geometries.Coordinate(coordscheck[0].X, coordscheck[0].Y); GeoAPI.Geometries.ILinearRing ring = gf.CreateLinearRing(coordscheck); pgcheck[i] = gf.CreatePolygon(ring, null); pg[i] = new Polygon(coord); } for (var t = 0; t < 49; t++) { var g = pg[t].Overlaps(pg[t + 1]); var gcheck = pgcheck[t].Overlaps(pgcheck[t + 1]); Assert.AreEqual(g, gcheck); } }
public void TestNamedMeridians() { foreach (Datum.NamedMeridian nm in Enum.GetValues(typeof(Datum.NamedMeridian))) { if (nm == Datum.NamedMeridian.Unknown || nm == Datum.NamedMeridian.Undefined) { continue; } var m = Datum.Meridian.CreateByNamedMeridian(nm); Assert.AreEqual((int)nm, m.Code); Assert.AreEqual(nm, m.Name); Assert.AreEqual(string.Format(" +pm={0}", nm.ToString().ToLower()), m.Proj4Description); var c = new GeoAPI.Geometries.Coordinate(0, 0); m.InverseAdjust(c); Assert.AreEqual(m.Longitude, c.X, 1e-7); m.Adjust(c); Assert.AreEqual(0, c.X, 1e-7); var m2 = Datum.Meridian.CreateByName(nm.ToString().ToLower()); Assert.AreEqual(m, m2); var m3 = Datum.Meridian.CreateByDegree(Utility.ProjectionMath.ToDegrees(m.Longitude)); Assert.AreEqual(m, m3); } }
public void PolygonArea() { var coords = new Coordinate[20]; var rnd = new Random(); var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var coordscheck = new GeoAPI.Geometries.Coordinate[20]; for (var i = 0; i < 19; i++) { coords[i] = new Coordinate(center.X + Math.Cos((i * 10) * Math.PI / 10), center.Y + (i * 10) * Math.PI / 10); var x = coords[i].X; var y = coords[i].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordscheck[i] = c; } coordscheck[19] = new GeoAPI.Geometries.Coordinate(coordscheck[0].X, coordscheck[0].Y); coords[19] = new Coordinate(coords[0].X, coords[0].Y); var gf = new NetTopologySuite.Geometries.GeometryFactory(); var ring = gf.CreateLinearRing(coordscheck); var polygonCheck = gf.CreatePolygon(ring, null); var pg = new Polygon(coords); var areaCheck = polygonCheck.Area; var area = pg.Area; Assert.IsTrue(Math.Abs(area - areaCheck) < 1e-6); }
public void MetersDistanceTest() { var brasiliaUtmZone = 23; var originCoordinateSystem = GeographicCoordinateSystem.WGS84; var targetCoordinateSystem = ProjectedCoordinateSystem.WGS84_UTM(brasiliaUtmZone, false); var transform = new CoordinateTransformationFactory().CreateFromCoordinateSystems( originCoordinateSystem, targetCoordinateSystem); var southCampus = new GeoAPI.Geometries.Coordinate(-15.8136081, -47.8442208); var northCampus = new GeoAPI.Geometries.Coordinate(-15.7632746, -47.8779637); var epnbCampus = new GeoAPI.Geometries.Coordinate(-15.87567632, -47.9929947); var southCoordinate = new GeoAPI.Geometries.Coordinate(southCampus.X, southCampus.Y); var northCoordinate = new GeoAPI.Geometries.Coordinate(northCampus.X, northCampus.Y); var epnbCoordinate = new GeoAPI.Geometries.Coordinate(epnbCampus.X, epnbCampus.Y); var newSouthCampusPoint = transform.MathTransform.Transform(southCoordinate); var newNorthCampusPoint = transform.MathTransform.Transform(northCoordinate); var newEnpbCampusPoint = transform.MathTransform.Transform(epnbCoordinate); var distanceSouthCampus = newEnpbCampusPoint.Distance(newSouthCampusPoint); var distanceNorthCampus = newEnpbCampusPoint.Distance(newNorthCampusPoint); distanceSouthCampus.ShouldBeGreaterThan(distanceNorthCampus); //result makes no sense for me, on google says other way }
public string findObject(Point point) { GeoAPI.Geometries.Coordinate pt = _sharpMap.ImageToWorld(point); string PointQ = "POINT(" + pt.X + " " + pt.Y + ")"; var placeQuery = " AND ST_DWithin(geom, ST_GeomFromText('" + PointQ + "',3005),0.0001) "; return(PointsTypes.findPoint(distanceQuery + placeQuery + intersectionQuery)); }
public Image recenterMap(int X, int Y) { GeoAPI.Geometries.Coordinate p = _sharpMap.ImageToWorld(new PointF(X, Y)); _sharpMap.Center.X = p.X; _sharpMap.Center.Y = p.Y; return(getMap()); }
public void PolygonHoles() { var coords = new Coordinate[20]; var rnd = new Random(); var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); // Shell Coordinates var coordscheck = new GeoAPI.Geometries.Coordinate[20]; for (var i = 0; i < 19; i++) { var x = center.X + Math.Cos((i * 10) * Math.PI / 10); var y = center.Y + (i * 10) * Math.PI / 10; coords[i] = new Coordinate(x, y); coordscheck[i] = new GeoAPI.Geometries.Coordinate(x, y); } coordscheck[19] = new GeoAPI.Geometries.Coordinate(coords[0].X, coords[0].Y); coords[19] = new Coordinate(coords[0].X, coords[0].Y); // Shell Rings var ring = new LinearRing(coords); var gf = new NetTopologySuite.Geometries.GeometryFactory(); var ringCheck = gf.CreateLinearRing(coordscheck); // Hole Coordinates var coordsholecheck = new GeoAPI.Geometries.Coordinate[20]; var coordshole = new Coordinate[20]; for (var i = 0; i < 20; i++) { var x = center.X + Math.Cos((i * 10) * Math.PI / 20); var y = center.Y + (i * 10) * Math.PI / 20; coordshole[i] = new Coordinate(x, y); coordsholecheck[i] = new GeoAPI.Geometries.Coordinate(x, y); } coordshole[19] = new Coordinate(coordshole[0].X, coordshole[0].Y); coordsholecheck[19] = new GeoAPI.Geometries.Coordinate(coordshole[0].X, coordshole[0].Y); // Hole LinearRing Arrays var hole = new LinearRing(coordshole); var holes = new ILinearRing[1]; var holeCheck = gf.CreateLinearRing(coordsholecheck); var holescheck = new GeoAPI.Geometries.ILinearRing[1]; holes[0] = hole; holescheck[0] = holeCheck; var pg = new Polygon(ring, holes); var polygonCheck = gf.CreatePolygon(ringCheck, holescheck); var areaCheck = polygonCheck.Area; var area = pg.Area; Assert.IsTrue(Math.Abs(area - areaCheck) < 1e-6); }
public static GeoAPI.Geometries.ILinearRing CreateRectangle(GeoAPI.Geometries.IGeometryFactory factory, GeoAPI.Geometries.Coordinate center, System.Drawing.SizeF size) { var wh = new System.Drawing.SizeF(size.Width * 0.5f, size.Height * 0.5f); var lt = new GeoAPI.Geometries.Coordinate(center.X - wh.Width, center.Y + wh.Height); var rb = new GeoAPI.Geometries.Coordinate(center.X + wh.Width, center.Y - wh.Height); return(CreateRectangle(factory, lt, rb)); }
public static double Distance3dBetweenPlaces(double lat1 , double lon1 , double lat2 , double lon2) { var pointACoordinate = new GeoAPI.Geometries.Coordinate(lat1, lon1, 0.0); var pointBCoordinate = new GeoAPI.Geometries.Coordinate(lat2, lon2, 0.0); return(pointACoordinate.Distance3D(pointBCoordinate)); }
/// <summary> /// Converts the given treeedge to a linestring. /// </summary> public static NetTopologySuite.Geometries.LineString ToLineString(this Algorithms.Networks.Analytics.Trees.Models.TreeEdge edge) { var coordinates = new GeoAPI.Geometries.Coordinate[edge.Shape.Length]; for (var i = 0; i < coordinates.Length; i++) { coordinates[i] = new GeoAPI.Geometries.Coordinate(edge.Shape[i][0], edge.Shape[i][1]); } return(new NetTopologySuite.Geometries.LineString(coordinates)); }
/// <summary> /// Initializes a new instance of the <see cref="T:CaiMCT.Clients.Portable.Geofence"/> class. /// </summary> /// <param name="name">Name.</param> /// <param name="coordinate">Coordinate.</param> /// <param name="meterRadius">Meter radius.</param> public Geofence(string name, GeoAPI.Geometries.Coordinate coordinate, double meterRadius) { Name = name; Point point = new Point(coordinate.X, coordinate.Y); BufferParameters bufferParams = new BufferParameters(16, GeoAPI.Operation.Buffer.EndCapStyle.Round, GeoAPI.Operation.Buffer.JoinStyle.Round, meterRadius); Polygon polygon = (Polygon)point.Buffer(meterRadius * metersToBufferDistanceConversionFactor, bufferParams); Geometry = polygon; }
private void MapBox1_MouseMove(GeoAPI.Geometries.Coordinate worldPos, MouseEventArgs imagePos) { //string x = worldPos.X.ToString(".00000"); //string y = worldPos.Y.ToString(".00000"); //labelAzimth.Text = x + "/" + y; if (myLat != 0.0 || myLon != 0.0) { labelAzimuth.Text = "Azimuth " + Azimuth(worldPos.Y, worldPos.X).ToString(".0"); } }
public void ReSize(int x, int y) { _Map.Size = new Size(x, y); _Map.ZoomToExtents(); GeoAPI.Geometries.Coordinate P1 = new GeoAPI.Geometries.Coordinate((140.0 + 6), (44.0 - 4)); //_Map.ImageToWorld(new PointF(100, 100)); _Map.Zoom = 90; _Map.Center = P1; zoom = _Map.Zoom; }
public static GeoAPI.Geometries.ILineString GetLineString(this Rct r) { GeoAPI.Geometries.Coordinate[] coords; coords = new GeoAPI.Geometries.Coordinate[5]; coords[0] = new GeoAPI.Geometries.Coordinate(r.TopLeft.X, r.TopLeft.Y); coords[1] = new GeoAPI.Geometries.Coordinate(r.TopRight.X, r.TopRight.Y); coords[2] = new GeoAPI.Geometries.Coordinate(r.BottomRight.X, r.BottomRight.Y); coords[3] = new GeoAPI.Geometries.Coordinate(r.BottomLeft.X, r.BottomLeft.Y); coords[4] = new GeoAPI.Geometries.Coordinate(r.TopLeft.X, r.TopLeft.Y); return(new NetTopologySuite.Geometries.LineString(coords)); }
public static double DistanceBetweenPlaces(double lat1 , double lon1 , double lat2 , double lon2) { // new GeoAPI.Geometries.Coordinate((double)coords[i].Latitude, (double)coords[i].Longitude, 0.0); var pointACoordinate = new GeoAPI.Geometries.Coordinate(lat1, lon1, 0.0); var pointBCoordinate = new GeoAPI.Geometries.Coordinate(lat2, lon2, 0.0); return(pointACoordinate.Distance(pointBCoordinate)); }
public static GeoAPI.Geometries.Coordinate[] ToNetTopologyCoordinates(this Wgs84Coordinates[] coords) //, int z) { GeoAPI.Geometries.Coordinate[] coordinates = new GeoAPI.Geometries.Coordinate[coords.Length]; for (int i = 0; i < coords.Length; ++i) { // coordinates[i]= FromWgs84(coords[0]); coordinates[i] = new GeoAPI.Geometries.Coordinate((double)coords[i].Latitude, (double)coords[i].Longitude, 0.0); } // Next i return(coordinates); } // End Function ToNetTopologyCoordinates
/// <summary> /// Converts this route to a feature collection. /// </summary> public static FeatureCollection ToFeatureCollection(this Route route) { var featureCollection = new FeatureCollection(); if (route.Shape == null) { return(featureCollection); } if (route.ShapeMeta == null) { // if there is no meta data, just use one linestring. var linestring = route.ToLineString(); var attributes = route.Attributes.ToAttributesTable(); featureCollection.Add(new Feature(linestring, attributes)); } else { // one linestring per meta-object. var previous = route.ShapeMeta[0]; for (var i = 1; i < route.ShapeMeta.Length; i++) { var current = route.ShapeMeta[i]; if (current.Shape < previous.Shape) { Logging.Logger.Log("RouteExtensions", Logging.TraceEventType.Warning, "Invalid meta-data detected on route. One of the meta-description has a shape index smaller than the previous one."); } var shape = new GeoAPI.Geometries.Coordinate[current.Shape - previous.Shape + 1]; for (var s = previous.Shape; s <= current.Shape; s++) { if (s < 0 || s >= route.Shape.Length) { throw new Exception("Invalid meta-data object: shape-index outside of the range of shapepoints."); } shape[s - previous.Shape] = route.Shape[s].ToCoordinate(); } var attributes = current.Attributes.ToAttributesTable(); featureCollection.Add(new Feature(new LineString(shape), attributes)); previous = current; } } if (route.Stops != null) { for (var i = 0; i < route.Stops.Length; i++) { featureCollection.Add(new Feature( new Point(new GeoAPI.Geometries.Coordinate( route.Stops[i].Coordinate.ToCoordinate())), route.Stops[i].Attributes.ToAttributesTable())); } } return(featureCollection); }
public static GeoAPI.Geometries.IPolygon GetPolygon(this Rect r) { GeoAPI.Geometries.Coordinate[] coords; coords = new GeoAPI.Geometries.Coordinate[5]; coords[0] = new GeoAPI.Geometries.Coordinate(r.Left, r.Top); coords[1] = new GeoAPI.Geometries.Coordinate(r.Right, r.Top); coords[2] = new GeoAPI.Geometries.Coordinate(r.Right, r.Bottom); coords[3] = new GeoAPI.Geometries.Coordinate(r.Left, r.Bottom); coords[4] = new GeoAPI.Geometries.Coordinate(r.Left, r.Top); return(new NetTopologySuite.Geometries.Polygon(new NetTopologySuite.Geometries.LinearRing(coords))); }
public void EnvelopeCoordinate() { var rnd = new Random(); var c = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var ev = new Envelope(c); var x = c.X; var y = c.Y; var ccheck = new GeoAPI.Geometries.Coordinate(x, y); var evcheck = new GeoAPI.Geometries.Envelope(ccheck); AssertExt.AreEqual15(ev.Maximum.Y, evcheck.MaxY); AssertExt.AreEqual15(ev.Maximum.X, evcheck.MaxX); AssertExt.AreEqual15(ev.Minimum.Y, evcheck.MinY); AssertExt.AreEqual15(ev.Minimum.X, evcheck.MinX); }
public void Buffer() { var rnd = new Random(); var coords = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var x = coords.X; var y = coords.Y; var c = new GeoAPI.Geometries.Coordinate(x, y); //coordscheck[i] = c; var p = new Point(coords); var gf = new NetTopologySuite.Geometries.GeometryFactory(); var ps = gf.CreatePoint(c); var area = p.Buffer(500).Area; var areacheck = ps.Buffer(500).Area; Assert.IsTrue(Math.Abs(area - areacheck) < 1e-6); }
protected void imgMap_Click(object sender, ImageClickEventArgs e) { //Set center of the map to where the client clicked //We set up a simple empty map so we can use the ImageToWorld() method for easy conversion from Image to World coordinates Map myMap = new Map(new Size(Convert.ToInt32(imgMap.Width.Value), Convert.ToInt32(imgMap.Height.Value))); myMap.Center = Center; myMap.Zoom = Zoom; Center = myMap.ImageToWorld(new System.Drawing.Point(e.X, e.Y)); //Set zoom value if any of the zoom tools were selected if (rblMapTools.SelectedValue == "0") //Zoom in Zoom = Zoom*0.5; else if (rblMapTools.SelectedValue == "1") //Zoom out Zoom = Zoom*2; //Create the map GenerateMap(); }
protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack) { //Page is post back. Restore center and zoom-values from viewstate Center = (Point) ViewState["mapCenter"]; Zoom = (double) ViewState["mapZoom"]; } else { //This is the initial view of the map. Center = new Point(12, 48); Zoom = 45; //Create the map GenerateMap(); } }
public void TwoCoordinates() { var rnd = new Random(); var c1 = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var c2 = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var ev = new Envelope(c1, c2); var x1 = c1.X; var y1 = c1.Y; var x2 = c2.X; var y2 = c2.Y; var c1Check = new GeoAPI.Geometries.Coordinate(x1, y1); var c2Check = new GeoAPI.Geometries.Coordinate(x2, y2); var evcheck = new GeoAPI.Geometries.Envelope(c1Check, c2Check); AssertExt.AreEqual15(ev.Maximum.Y, evcheck.MaxY); AssertExt.AreEqual15(ev.Maximum.X, evcheck.MaxX); AssertExt.AreEqual15(ev.Minimum.Y, evcheck.MinY); AssertExt.AreEqual15(ev.Minimum.X, evcheck.MinX); }
public void LineLength() { var coords = new Coordinate[36]; var rnd = new Random(); var coordscheck = new GeoAPI.Geometries.Coordinate[36]; for (var i = 0; i < 36; i++) { coords[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var x = coords[i].X; var y = coords[i].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordscheck[i] = c; } var gf = new NetTopologySuite.Geometries.GeometryFactory(); var lscheck = gf.CreateLineString(coordscheck); var ls = new LineString(coords); var length = ls.Length; var lengthcheck = lscheck.Length; Assert.AreEqual(length, lengthcheck); }
public void Intersection() { var rnd = new Random(); var pg = new Polygon[50]; var pgcheck = new GeoAPI.Geometries.IPolygon[50]; var gf = new NetTopologySuite.Geometries.GeometryFactory(); var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); for (var i = 0; i < 50; i++) { var coord = new Coordinate[36]; var coordscheck = new GeoAPI.Geometries.Coordinate[36]; for (var ii = 0; ii < 36; ii++) { coord[ii] = new Coordinate(center.X + Math.Cos((ii * 10) * Math.PI / 10), center.Y + (ii * 10) * Math.PI / 10); var x = coord[ii].X; var y = coord[ii].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordscheck[ii] = c; } coord[35] = new Coordinate(coord[0].X, coord[0].Y); coordscheck[35] = new GeoAPI.Geometries.Coordinate(coordscheck[0].X, coordscheck[0].Y); GeoAPI.Geometries.ILinearRing ring = gf.CreateLinearRing(coordscheck); pgcheck[i] = gf.CreatePolygon(ring, null); pg[i] = new Polygon(coord); } for (var t = 0; t < 49; t++) { var g = pg[t].Intersection(pg[t + 1]); var gcheck = pgcheck[t].Intersection(pgcheck[t + 1]); for (var j = 0; j < g.Coordinates.Count; j++) { Assert.AreEqual(g.Coordinates[j].X, gcheck.Coordinates[j].X); Assert.AreEqual(g.Coordinates[j].Y, gcheck.Coordinates[j].Y); } } }
public void MultiPs() { var c = new Coordinate[36]; var rnd = new Random(); var ccheck = new GeoAPI.Geometries.Coordinate[36]; var gf = new NetTopologySuite.Geometries.GeometryFactory(); for (var i = 0; i < 36; i++) { c[i] = new Coordinate((rnd.NextDouble() + 360) - 180, (rnd.NextDouble() * 180) - 90); var x = c[i].X; var y = c[i].Y; var ctemp = new GeoAPI.Geometries.Coordinate(x, y); ccheck[i] = ctemp; } GeoAPI.Geometries.IMultiPoint mpsCheck = gf.CreateMultiPoint(ccheck); var mps = new MultiPoint(c); for (var ii = 0; ii < mps.Coordinates.Count; ii++) { Assert.AreEqual(mps.Coordinates[ii].X, mpsCheck.Coordinates[ii].X); Assert.AreEqual(mps.Coordinates[ii].Y, mpsCheck.Coordinates[ii].Y); } }
public static GeoAPI.Geometries.ILinearRing CreateEllipse(GeoAPI.Geometries.IGeometryFactory factory, GeoAPI.Geometries.Coordinate center, System.Drawing.SizeF size, int segmentsPerQuadrant) { const double piHalf = System.Math.PI * 0.5d; var step = piHalf / segmentsPerQuadrant; var pts = new GeoAPI.Geometries.Coordinate[4 * segmentsPerQuadrant + 1]; var angle = 0d; for (var i = 0; i < 4 * segmentsPerQuadrant; i++) { pts[i] = new GeoAPI.Geometries.Coordinate(center.X + System.Math.Cos(angle) * size.Width, center.Y + System.Math.Sin(angle) * size.Height); angle += step; } pts[pts.Length - 1] = pts[0]; return factory.CreateLinearRing(pts); }
public void Center() { var rnd = new Random(); var c1 = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var c2 = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var ev = new Envelope(c1, c2); var x1 = c1.X; var y1 = c1.Y; var x2 = c2.X; var y2 = c2.Y; var c1Check = new GeoAPI.Geometries.Coordinate(x1, y1); var c2Check = new GeoAPI.Geometries.Coordinate(x2, y2); var evcheck = new GeoAPI.Geometries.Envelope(c1Check, c2Check); var center = new Coordinate(ev.Center()); var centercheck = new GeoAPI.Geometries.Coordinate(evcheck.Centre); AssertExt.AreEqual15(center.X, centercheck.X); AssertExt.AreEqual15(center.Y, centercheck.Y); }
public void LineEndPoint() { var coords = new Coordinate[36]; var rnd = new Random(); var coordscheck = new GeoAPI.Geometries.Coordinate[36]; for (var i = 0; i < 36; i++) { coords[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var x = coords[i].X; var y = coords[i].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordscheck[i] = c; } var gf = new NetTopologySuite.Geometries.GeometryFactory(); var lscheck = gf.CreateLineString(coordscheck); var ls = new LineString(coords); AssertExt.AreEqual15(ls.EndPoint.X, lscheck.EndPoint.X); AssertExt.AreEqual15(ls.EndPoint.Y, lscheck.EndPoint.Y); }
public void PolygonShellEndPoint() { var coords = new Coordinate[20]; var rnd = new Random(); var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var coordscheck = new GeoAPI.Geometries.Coordinate[20]; for (var i = 0; i < 19; i++) { coords[i] = new Coordinate(center.X + Math.Cos((i * 10) * Math.PI / 10), center.Y + (i * 10) * Math.PI / 10); var x = coords[i].X; var y = coords[i].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordscheck[i] = c; } coordscheck[19] = new GeoAPI.Geometries.Coordinate(coords[0].X, coords[0].Y); coords[19] = new Coordinate(coords[0].X, coords[0].Y); var gf = new NetTopologySuite.Geometries.GeometryFactory(); var ring = gf.CreateLinearRing(coordscheck); var polygonCheck = gf.CreatePolygon(ring, null); var pg = new Polygon(coords); AssertExt.AreEqual15(pg.Shell.EndPoint.X, polygonCheck.Shell.EndPoint.X); AssertExt.AreEqual15(pg.Shell.EndPoint.Y, polygonCheck.Shell.EndPoint.Y); }
public void BufferLength() { var rnd = new Random(); var coords = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var x = coords.X; var y = coords.Y; var c = new GeoAPI.Geometries.Coordinate(x, y); //coordscheck[i] = c; var p = new Point(coords); var gf = new NetTopologySuite.Geometries.GeometryFactory(); var ps = gf.CreatePoint(c); var boundary = p.Buffer(500).Length; var boundarycheck = ps.Buffer(500).Length; AssertExt.AreEqual15(boundary, boundarycheck); }
private void LoadParcels(List<PointD> pt, Color color, string labelname) { SharpMap.Map map = new SharpMap.Map(); List<GeoAPI.Geometries.Coordinate> vertices = new List<GeoAPI.Geometries.Coordinate>(); foreach (PointD i in pt) { GeoAPI.Geometries.Coordinate p = new GeoAPI.Geometries.Coordinate(); p.X = i.X; p.Y = i.Y; vertices.Add(p); } GeoAPI.Geometries.Coordinate l = new GeoAPI.Geometries.Coordinate(); l.X = pt[0].X; l.Y = pt[0].Y; vertices.Add(l); //Collection<GeoAPI.Geometries.IGeometry> geom = new Collection<GeoAPI.Geometries.IGeometry>(); GeometryFactory gf = new NetTopologySuite.Geometries.GeometryFactory(); GeoAPI.Geometries.ILinearRing shell = gf.CreateLinearRing(vertices.ToArray()); GeoAPI.Geometries.IPolygon polygon = gf.CreatePolygon(shell, null); SharpMap.Data.Providers.GeometryProvider geomProvider= new SharpMap.Data.Providers.GeometryProvider(polygon); SharpMap.Layers.VectorLayer layerParcels = new SharpMap.Layers.VectorLayer("Parcels"); SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle(); style.Fill = new SolidBrush(Color.FromArgb(200,color)); style.Outline = new Pen(new SolidBrush(color)); layerParcels.Style = style; layerParcels.Style.EnableOutline = true; layerParcels.DataSource = geomProvider; layerParcels.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan; var fdt = new SharpMap.Data.FeatureDataTable(); fdt.Columns.Add(new System.Data.DataColumn("id", typeof(uint))); fdt.Columns.Add(new System.Data.DataColumn("label", typeof(string))); var fdr = (SharpMap.Data.FeatureDataRow)fdt.NewRow(); fdr.ItemArray = new object[] { 1, labelname }; fdr.Geometry = polygon; fdt.AddRow(fdr); var dataprovider = new SharpMap.Data.Providers.GeometryFeatureProvider(fdt); var ll = new SharpMap.Layers.LabelLayer("llayer"); ll.DataSource = dataprovider; ll.LabelColumn = "label"; ll.Style.Font = new Font("Eurostile Extended", 16,FontStyle.Bold); mapBox1.Map.Layers.Add(layerParcels); mapBox1.Map.Layers.Add(ll); mapBox1.Map.ZoomToExtents(); mapBox1.Refresh(); }
public void PolygonEnvelopeMaxMin() { var coords = new Coordinate[20]; var rnd = new Random(); var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var coordscheck = new GeoAPI.Geometries.Coordinate[20]; for (var i = 0; i < 19; i++) { coords[i] = new Coordinate(center.X + Math.Cos((i * 10) * Math.PI / 10), center.Y + (i * 10) * Math.PI / 10); var x = coords[i].X; var y = coords[i].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordscheck[i] = c; } coordscheck[19] = new GeoAPI.Geometries.Coordinate(coords[0].X, coords[0].Y); coords[19] = new Coordinate(coords[0].X, coords[0].Y); var gf = new NetTopologySuite.Geometries.GeometryFactory(); GeoAPI.Geometries.ILinearRing ring = gf.CreateLinearRing(coordscheck); GeoAPI.Geometries.IPolygon pgcheck = gf.CreatePolygon(ring, null); var pg = new Polygon(coords); AssertExt.AreEqual15(pg.Envelope.Maximum.X, pgcheck.EnvelopeInternal.MaxX); AssertExt.AreEqual15(pg.Envelope.Maximum.Y, pgcheck.EnvelopeInternal.MaxY); AssertExt.AreEqual15(pg.Envelope.Minimum.X, pgcheck.EnvelopeInternal.MinX); AssertExt.AreEqual15(pg.Envelope.Minimum.Y, pgcheck.EnvelopeInternal.MinY); }
public static GeoAPI.Geometries.ILinearRing CreateRectangle(GeoAPI.Geometries.IGeometryFactory factory, GeoAPI.Geometries.Coordinate center, System.Drawing.SizeF size) { var wh = new System.Drawing.SizeF(size.Width * 0.5f, size.Height * 0.5f); var lt = new GeoAPI.Geometries.Coordinate(center.X - wh.Width, center.Y + wh.Height); var rb = new GeoAPI.Geometries.Coordinate(center.X + wh.Width, center.Y - wh.Height); return CreateRectangle(factory, lt, rb); }
public void LineStringEnvelopeHeightWidth() { var coords = new Coordinate[36]; var rnd = new Random(); var coordscheck = new GeoAPI.Geometries.Coordinate[36]; for (var i = 0; i < 36; i++) { coords[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var x = coords[i].X; var y = coords[i].Y; var c = new GeoAPI.Geometries.Coordinate(x, y); coordscheck[i] = c; } var gf = new NetTopologySuite.Geometries.GeometryFactory(); GeoAPI.Geometries.ILineString lscheck = gf.CreateLineString(coordscheck); var ls = new LineString(coords); AssertExt.AreEqual15(ls.Envelope.Width, lscheck.EnvelopeInternal.Width); AssertExt.AreEqual15(ls.Envelope.Height, lscheck.EnvelopeInternal.Height); }
public void MpsBufferArea() { var c = new Coordinate[36]; var rnd = new Random(); var ccheck = new GeoAPI.Geometries.Coordinate[36]; var gf = new NetTopologySuite.Geometries.GeometryFactory(); for (var i = 0; i < 36; i++) { c[i] = new Coordinate((rnd.NextDouble() + 360) - 180, (rnd.NextDouble() * 180) - 90); var x = c[i].X; var y = c[i].Y; var ctemp = new GeoAPI.Geometries.Coordinate(x, y); ccheck[i] = ctemp; } GeoAPI.Geometries.IMultiPoint mpsCheck = gf.CreateMultiPoint(ccheck); var mps = new MultiPoint(c); var area = mps.Buffer(500).Area; var areacheck = mpsCheck.Buffer(500).Area; Assert.IsTrue(Math.Abs(area - areacheck) < 1e-6 ); }