Beispiel #1
0
        protected override void OnMouseDown(GeoMouseArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                _isEnabled    = false;
                _currentPoint = e.Location;
                int x = _currentPoint.X;
                int y = _currentPoint.Y;
                System.Drawing.Point point = new System.Drawing.Point(x, y);
                _points           = point;
                _coordinatePoints = this._map.PixelToProj(new System.Drawing.Point(_points.X, _points.Y));

                IMapPointLayer pointLayer = GetPointLayer();
                _point = new NetTopologySuite.Geometries.Point(_coordinatePoints);
                pointLayer.DataSet.AddFeature(_point as IGeometry);

                _map.Refresh();
                _isEnabled = true;
            }
            else if (e.Button == MouseButtons.Right)
            {
                this.Enabled = false;
                string bufferType  = "PointBuffer";
                Buffer pointBuffer = new Buffer(bufferType);
                pointBuffer.ShowDialog();
                _map.FunctionMode = FunctionMode.Pan;
            }

            base.OnMouseDown(e);
        }
Beispiel #2
0
 public static bool IsNodeInBuilding(Node node, ICompleteOsmGeo building)
 {
     if (building is Node buildingNode)
     {
         return(DistanceMeters(node, buildingNode) <= 1);
     }
     else if (building is CompleteWay buildingWay)
     {
         var point = new NetTopologySuite.Geometries.Point(node.Longitude.Value, node.Latitude.Value);
         if (buildingWay.Nodes.Length < 4 || (buildingWay.Nodes.First() != buildingWay.Nodes.Last()))
         {
             return(false);
         }
         var ring = new NetTopologySuite.Geometries.LinearRing(
             buildingWay.Nodes.Select(n => new Coordinate(n.Longitude.Value, n.Latitude.Value)).ToArray());
         var polygon = new NetTopologySuite.Geometries.Polygon(ring);
         return(point.Within(polygon));
     }
     else if (building is CompleteRelation buildingRelation)
     {
         // "in" means that even if I land in the center of a donut, I'm still "in" the building.
         // This isn't 100% accurate (false negative) for polygons where the closed outer ring is defined by more than 2 open ways.
         return(buildingRelation.Members.Any(m => m.Role != "inner" && IsNodeInBuilding(node, m.Member)));
     }
     throw new Exception("ICompleteOsmGeo wasn't a Node, Way or Relation.");
 }
Beispiel #3
0
        public async Task <IEnumerable <HospitalViewModel> > GetHospitalsInRadius(double x, double y, double radius)
        {
            var point = new Point(x, y)
            {
                SRID = 4326
            };
            var hospitals =
                await _hospitalRepository
                .GetWithFilter(h => h.Location.Distance(point) <= radius)
                .ToListAsync();

            return(hospitals.Select(h => new HospitalViewModel
            {
                Id = h.Id,
                Name = h.Name,
                CNPJ = h.CNPJ,
                Location = new PointViewModel
                {
                    X = h.Location.X,
                    Y = h.Location.Y
                },
                QueueSize = _appointmentRepository.GetWithFilter(a => a.IdHospital == h.Id && a.EndDate == null).Count(),
                Distance = h.Location.DistanceInMeters(point)
            }));
        }
Beispiel #4
0
        public void CheckIsPointInRegion(double x, double y)
        {
            var geom = new NetTopologySuite.Geometries.Polygon(
                new LinearRing(new Coordinate[]
            {
                //逆时针绘制
                new Coordinate(10, 0),
                new Coordinate(10, 10),
                new Coordinate(0, 10),
                new Coordinate(0, 0),
                new Coordinate(10, 0),
            }));

            //设置坐标系
            geom.SRID = srid;
            var point = new NetTopologySuite.Geometries.Point(x, y)
            {
                SRID = srid
            };
            //https://stackoverflow.com/questions/53820355/fast-find-if-points-belong-to-polygon-nettopologysuite-geometries-c-net-cor
            var prepGeom  = NetTopologySuite.Geometries.Prepared.PreparedGeometryFactory.Prepare(geom);
            var isContain = prepGeom.Contains(point);

            Console.WriteLine(isContain ? $"点({x},{y})包含在面以内" : $"点({x},{y})不包含在面以内");
        }
Beispiel #5
0
 private void drawPoint(Point p)
 {
     p = (Point)GeometryTransform.TransformGeometry(p, LayerTools.Wgs84toGoogleMercator.MathTransform, geofactory);
     markerProvider.Geometries.Add(p);
     // include(p);
     RefreshMap();
 }
Beispiel #6
0
        /// <summary>
        /// Converts a WGS-84 Lat/Long coordinate to the tile XY of the tile containing that point at the given levelOfDetail.
        /// </summary>
        /// <param name="coord">WGS-84 Lat/Long.</param>
        /// <param name="levelOfDetail">Level of detail, from 1 (lowest detail) to 23 (highest detail).</param>
        /// <returns>Tile XY Point.</returns>
        public static NtsPoint LatLongToTileXy(Coordinate coord, int levelOfDetail)
        {
            NtsPoint pixelXy = LatLongToPixelXy(coord.Y, coord.X, levelOfDetail);
            NtsPoint tileXy  = PixelXyToTileXy(pixelXy);

            return(tileXy);
        }
        static void ReadCities()
        {
            using (var db = new Tests.PostGisTestDataConnection(ConnectionString))
            {
                var point = new NTSGS.Point(new NTSGS.Coordinate(0, 7200000))
                {
                    SRID = 3857
                };

                var nearestCity = db.OwmCities
                                  .OrderBy(c => c.Geometry.STDistance(point))
                                  .First();
                Console.WriteLine($"Nearest city: [{nearestCity.Id}] '{nearestCity.Name}'");

                var query = db.OwmCities
                            .Select(c =>
                                    new
                {
                    Id        = c.Id,
                    Name      = c.Name,
                    NumPoints = c.Geometry.STNPoints(),
                    Srid      = c.Geometry.STSrId(),
                    Area      = c.Geometry.STArea(),
                    Distance  = c.Geometry.STDistance(point),
                    Wkt       = c.Geometry.STAsText(),
                    EWkt      = c.Geometry.STAsEWKT(),
                });

                var list = query.ToList();
                foreach (var c in list)
                {
                    Console.WriteLine($"[{c.Id}] '{c.Name}'\tDistance: {c.Distance:0}\tSRID={c.Srid}\t{c.Wkt}");
                }
            }
        }
Beispiel #8
0
        /// <summary>
        /// Distances the specified other.
        /// </summary>
        /// <param name="other">The other.</param>
        /// <returns></returns>
        public double Distance(LatLonAlt other)
        {
            NetTopologySuite.Geometries.Point p1 = new NetTopologySuite.Geometries.Point(Lon, Lat);
            NetTopologySuite.Geometries.Point p2 = new NetTopologySuite.Geometries.Point(other.Lon, other.Lat);

            return(p1.Distance(p2));
        }
        internal static double STDistance(object instanceA, object instanceB)
        {
            NetTopologySuite.Geometries.Point pointA = null;
            NetTopologySuite.Geometries.Point pointB = null;
            if (!STGeometryType(instanceA).Equals("Point"))
            {
                pointA = ((Geometry)instanceA).InteriorPoint;
            }
            else
            {
                pointA = (Point)instanceA;
            }
            if (!STGeometryType(instanceB).Equals("Point"))
            {
                pointB = ((Geometry)instanceB).InteriorPoint;
            }
            else
            {
                pointB = (Point)instanceB;
            }
            double   LatA = pointA.Y;
            double   LonA = pointA.X;
            double   LatB = pointB.Y;
            double   LonB = pointB.X;
            Geodesic g    = Geodesic.WGS84;
            var      dt   = g.Inverse(LatA, LonA, LatB, LonB);

            return(dt.s12);
        }
        public void TestSTDistance()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                var point = new NTSG.Point(new NTSG.Coordinate(-72.1235, 42.3521))
                {
                    SRID = SRID4326
                };
                db.Insert(new TestGeometryEntity(1, point));
                var lineString = new NTSG.LineString(new[] { new NTSG.Coordinate(-72.1260, 42.45), new NTSG.Coordinate(-72.123, 42.1546) })
                {
                    SRID = SRID4326
                };
                db.Insert(new TestGeometryEntity(2, lineString));

                // Geometry example - units in planar degrees 4326 is WGS 84 long lat, units are degrees.
                var distances4326 = db.TestGeometries.Select(g => g.Geometry.STDistance(point)).ToList();

                Assert.AreEqual(2, distances4326.Count);
                Assert.AreEqual(0.0, distances4326[0]);
                Assert.AreEqual(0.00150567726382822, distances4326[1], 1.0E9);

                // Geometry example - units in meters (SRID:3857, proportional to pixels on popular web maps).
                var distances3857 = db.TestGeometries.Select(g => g.Geometry.STTransform(SRID3857).STDistance(point.STTransform(SRID3857))).ToList();

                Assert.AreEqual(2, distances3857.Count);
                Assert.AreEqual(0.0, distances3857[0]);
                Assert.AreEqual(167.441410065196, distances3857[1], 1.0E9);

                var nullDistance = db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STDistance(null)).Single();
                Assert.IsNull(nullDistance);
            }
        }
Beispiel #11
0
        private static NTSPolygon DrawCircle(IPoint center, double radius, int verticesPerQuarter)
        {
            var point    = new NTSPoint(center.X, center.Y);
            var geometry = point.Buffer(radius, verticesPerQuarter);

            return(new NetTopologySuite.Geometries.Polygon(new LinearRing(geometry.Coordinates)));
        }
        public void TestSTDisjoint()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Wkt1 = "LINESTRING ( 2 0, 0 2 )";
                db.TestGeometries.Value(g => g.Id, 1).Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt1)).Insert();

                const string Wkt2 = "LINESTRING ( 0 0, 0 2 )";
                db.TestGeometries.Value(g => g.Id, 2).Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt2)).Insert();

                const string PointWkt = "POINT(0 0)";
                var          point    = new NTSGS.Point(new NTSGS.Coordinate(0, 0));
                Assert.IsTrue(db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STDisjoint(point)).Single());
                Assert.IsFalse(db.TestGeometries.Where(g => g.Id == 2).Select(g => g.Geometry.STDisjoint(point)).Single());
                Assert.IsNull(db.TestGeometries.Where(g => g.Id == 1).Select(g => g.Geometry.STDisjoint(null)).Single());


                // TODO: need explicit cast text to geometry
                if (this.CurrentVersion >= new Version("3.0.0"))
                {
                    Assert.IsTrue(db.Select(() => SpatialRelationships.STDisjoint(Wkt1, PointWkt)));
                    Assert.IsFalse(db.Select(() => SpatialRelationships.STDisjoint(Wkt2, PointWkt)));
                }
            }
        }
Beispiel #13
0
        public void drawPoint(IEnumerable <Point> points, PointType type = PointType.Image)
        {
            foreach (Point p in points)
            {
                Point tmp_p = (Point)GeometryTransform.TransformGeometry(p, LayerTools.Wgs84toGoogleMercator.MathTransform, geofactory);
                switch (type)
                {
                case PointType.Image:
                {
                    markerProvider.Geometries.Add(tmp_p);
                    break;
                }

                case PointType.GreenPoint:
                {
                    greenPointProvider.Geometries.Add(tmp_p);
                    break;
                }

                case PointType.RedPoint:
                {
                    redPointProvider.Geometries.Add(tmp_p);
                    break;
                }
                }
                // include(tmp_p);
            }
            RefreshMap();
        }
Beispiel #14
0
        private void mbMap_MouseMove(Coordinate worldPos, MouseEventArgs imagePos)
        {
            Point p = new Point(worldPos);

            p = GeometryTransform.TransformGeometry(p, LayerTools.GoogleMercatorToWgs84.MathTransform, geofactory) as Point;
            lbPosition.Text = String.Format("X:{0:#.000000}\nY: {1:#.000000}", p.X, p.Y);
            //lbPosition.Text = String.Format("X:{0}\nY:{1}", worldPos.X, worldPos.Y);
        }
Beispiel #15
0
        private IFeature ExtractGeographicData(XmlNode c)
        {
            string   geoData = string.Empty;
            Geometry geo     = null;

            if (_typeGeometry == FeatureType.Point)
            {
                foreach (XmlNode e in c)
                {
                    if (e.LocalName == Geometry)
                    {
                        geoData = e.InnerText;
                    }
                }

                string point      = Convert.ToString(geoData);
                var    pointValue = point.Split(' ');
                geo = new NtsPoint(
                    Convert.ToDouble(pointValue[0], CultureInfo.InvariantCulture),
                    Convert.ToDouble(pointValue[1], CultureInfo.InvariantCulture));
            }

            if (_typeGeometry == FeatureType.Polygon)
            {
                foreach (XmlNode e in c)
                {
                    if (e.LocalName == Geometry)
                    {
                        var t = e.FirstChild.OuterXml;
                        var s = new XmlSerializer(typeof(MultiSurfaceType));
                        MultiSurfaceType multi = s.Deserialize(new StringReader(t)) as MultiSurfaceType;
                        geo = GetPolygon(multi);

                        // geoData = e.InnerText;
                    }
                }
            }

            if (_typeGeometry == FeatureType.Line)
            {
                foreach (XmlNode e in c)
                {
                    if (e.LocalName == Geometry)
                    {
                        var t = e.FirstChild.OuterXml;
                        var s = new XmlSerializer(typeof(MultiLineStringType));
                        MultiLineStringType multi = s.Deserialize(new StringReader(t)) as MultiLineStringType;
                        geo = GetPolyline(multi);

                        // geoData = e.InnerText;
                    }
                }
            }

            IFeature feat = Fea.AddFeature(geo);

            return(feat);
        }
 public void gml_reader_can_read_gml_fragment()
 {   
     GMLReader reader = new GMLReader();
     string testFragment = GenerateTestFragment();
     IGeometry actual = reader.Read(testFragment);
     Assert.That(actual, Is.Not.Null);
     Point geom = new Point(52, -0.9);
     Assert.That(actual.EqualsExact(geom), Is.True);
 }
Beispiel #17
0
        public static void DrawPoint(PointSymbolizer symbolizer, Graphics g, Point point, MapViewport map)
        {
            if (point == null)
            {
                return;
            }

            symbolizer.Render(map, point, g);
        }
Beispiel #18
0
 // transforms real world point to screen point
 public NTSPoint ScaleAndOffSet(NTSPoint pt)
 {
     NTSPoint p = new NTSPoint(0, 0);
     p.X = pt.X - offset.X;
     p.Y = pt.Y - offset.Y;
     p.X *= scale.X;
     p.Y *= scale.Y;
     return p;
 }
Beispiel #19
0
 public MapLocation(Individual ind, Fact fact, FactLocation loc, FactDate year)
 {
     Individual    = ind;
     Fact          = fact;
     Location      = loc;
     _year         = year;
     Icon          = FactLocationImage.ErrorIcon(loc.GeocodeStatus).Icon;
     Geometry      = new NetTopologySuite.Geometries.Point(Location.LongitudeM, Location.LatitudeM);
     FoundLocation = loc.FoundLocation;
 }
Beispiel #20
0
        /// <summary>
        /// 缩放视图以使地图包容p
        /// </summary>
        /// <param name="e"></param>
        private void include(Point p)
        {
            Envelope box = mbMap.Map.Envelope;

            if (!box.Contains(p.Coordinate))
            {
                box = box.Merge(p);
                mbMap.Map.ZoomToBox(box);
                RefreshMap();
            }
        }
        public void TestSTIntersects()
        {
            using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString))
            {
                const string Wkt1 = "LINESTRING ( 2 0, 0 2 )";
                db.TestGeometries.Value(g => g.Id, 1).Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt1)).Insert();

                const string Wkt2 = "LINESTRING ( 0 0, 0 2 )";
                db.TestGeometries.Value(g => g.Id, 2).Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt2)).Insert();

                const string PointWkt = "POINT(0 0)";
                var          point    = new NTSGS.Point(new NTSGS.Coordinate(0, 0));

                Assert.IsFalse(db.TestGeometries
                               .Where(g => g.Id == 1)
                               .Select(g => g.Geometry.STIntersects(point))
                               .Single());

                Assert.IsTrue(db.TestGeometries
                              .Where(g => g.Id == 2)
                              .Select(g => g.Geometry.STIntersects(point))
                              .Single());

                Assert.IsNull(db.TestGeometries
                              .Where(g => g.Id == 2)
                              .Select(g => g.Geometry.STIntersects(null))
                              .Single());

                Assert.IsFalse(db.Select(() => SpatialRelationships.STIntersects(Wkt1, PointWkt)));
                Assert.IsTrue(db.Select(() => SpatialRelationships.STIntersects(Wkt2, PointWkt)));
                Assert.IsNull(db.Select(() => SpatialRelationships.STIntersects((string)null, (string)null)));

                // geography
                var lineGeography = new NTSGS.LineString(new[] { new NTSGS.Coordinate(-43.23456, 72.4567), new NTSGS.Coordinate(-43.23456, 72.4568) })
                {
                    SRID = SRID4326
                };
                db.Insert(new TestGeographyEntity(1, lineGeography));

                var pointGeography = new NTSGS.Point(-43.23456, 72.4567)
                {
                    SRID = SRID4326
                };
                db.Insert(new TestGeographyEntity(2, pointGeography));

                var intersects = db.TestGeographies
                                 .Where(g => g.Id == 1)
                                 .Select(g => g.Geography.STIntersects(db.TestGeographies.Where(g0 => g0.Id == 2).Single().Geography))
                                 .Single();

                Assert.IsTrue(intersects);
            }
        }
Beispiel #22
0
        /// <summary>
        /// 扩充box使其包容点
        /// </summary>
        /// <param name="b1"></param>
        /// <param name="b2"></param>
        /// <returns></returns>
        public static Envelope Merge(this Envelope b, Point p)
        {
            Envelope result;
            double   minX, minY, maxX, maxY;

            minX   = Math.Min(b.MinX, p.X);
            minY   = Math.Min(b.MinY, p.Y);
            maxX   = Math.Max(b.MaxX, p.X);
            maxY   = Math.Max(b.MaxY, p.Y);
            result = new Envelope(minX, maxX, minY, maxY);
            return(result);
        }
Beispiel #23
0
 public Location(
     string address, string suburb, string city, string country, string postcode, double latitude, double longitude)
     : base()
 {
     Address = address;
     Suburb = suburb;
     City = city;
     Country = country;
     Postcode = postcode;
     Latitude = latitude;
     Longitude = longitude;
     GeoLoc = new Point(longitude, latitude);
 }
Beispiel #24
0
        private void PrepareMap(Symbol symbol)
        {
            _map.Clear();

            Layer layer = new Layer("__swatch", LayerType.Acetate);

            switch (symbol.GetType().Name)
            {
            case "SimplePolygonSymbol":
            case "GradientFillSymbol":
            case "RasterFillSymbol":
                double minx = _margin + 0.4999;
                double miny = _margin + 0.4999;
                double maxx = _width - _margin - 0.4999;
                double maxy = _height - _margin - 0.4999;

                IPolygon polygon = new Polygon(new LinearRing(new Coordinate[] {
                    new Coordinate(minx, miny),
                    new Coordinate(minx, maxy),
                    new Coordinate(maxx, maxy),
                    new Coordinate(maxx, miny),
                    new Coordinate(minx, miny)
                }));

                layer.Add(polygon, symbol);
                break;

            case "SimpleLineSymbol":
            case "HashLineSymbol":
                ILineString lineString = new LineString(new Coordinate[] {
                    new Coordinate(_margin, _height / 2),
                    new Coordinate(_width - _margin - 1, _height / 2)
                });
                layer.Add(lineString, symbol);
                break;

            case "SimpleMarkerSymbol":
            case "TrueTypeMarkerSymbol":
            case "RasterMarkerSymbol":
                IPoint p = new NetTopologySuite.Geometries.Point(_width / 2, _height / 2);
                layer.Add(p, symbol);
                break;
            }

            _map.BackgroundColor = BackgroundColor;

            if (layer.Objects != null)
            {
                _map.AddLayer(layer);
            }
        }
        private static string GenerateTestFragment()
        {
            StringBuilder sb = new StringBuilder();
            XmlTextWriter writer = new XmlTextWriter(new StringWriter(sb));
            writer.WriteStartElement("test");
            writer.WriteAttributeString("xmlns", "gml", null, "http://www.opengis.net/gml");

            Point geom = new Point(52, -0.9);
            GMLWriter gmlWriter = new GMLWriter();
            gmlWriter.Write(geom, writer);

            writer.WriteEndElement();
            return sb.ToString();
        }
Beispiel #26
0
        private static List <Coordinate> CreatePointsSet(RadioInfo radio, bool project, ref double xMin, ref double xMax, ref double yMin, ref double yMax, Polygon polygon)
        {
            if (polygon[0] != polygon[polygon.Count - 1])
            {
                if (polygon.Count == 2)
                {
                    // le hace triángulo
                    polygon.Add(new System.Drawing.Point(polygon[0].X, polygon[1].Y));
                }
                polygon.Add(polygon[0]);
            }
            //////////////////////
            Coordinate from   = radio.GetFrom();
            Coordinate to     = radio.GetTo();
            double     xScale = (to.X - from.X) / radio.ImageExtents.Width;
            double     yScale = (to.Y - from.Y) / radio.ImageExtents.Height;

            List <Coordinate> puntos = new List <Coordinate>();
            IPoint            lastP  = null;

            foreach (System.Drawing.Point p in polygon)
            {
                var newPoint = new NetTopologySuite.Geometries.Point(xScale * p.X +
                                                                     from.X, yScale * (radio.ImageExtents.Height - p.Y) + from.Y);
                IPoint point;
                if (project)
                {
                    point = Projections.UnprojectPoint(newPoint, Context.Projection);
                }
                else
                {
                    point = newPoint;
                }

                xMin = Math.Min(point.X, xMin);
                xMax = Math.Max(point.X, xMax);

                yMin = Math.Min(point.Y, yMin);
                yMax = Math.Max(point.Y, yMax);

                puntos.Add(new Coordinate(point.X, point.Y));
                if (lastP != null)
                {
                    radio.TotalPerimeter += PolygonFinder.EuclideanDist(point, lastP);
                }

                lastP = point;
            }
            return(puntos);
        }
        public void gml_writer_generates_fragment_with_namespace_if_needed()
        {            
            XmlDocument doc = new XmlDocument();
            Point geom = new Point(52, -0.9);
            doc.Load(geom.ToGMLFeature());

            string content = doc.OuterXml;
            Assert.That(content, Is.Not.Null);
            Assert.That(content.StartsWith("<gml:Point xmlns:gml=\"http://www.opengis.net/gml\""), Is.True);

            GMLReader reader = new GMLReader();
            IGeometry actual = reader.Read(content);
            Assert.That(actual, Is.Not.Null);
            Assert.That(actual.EqualsExact(geom), Is.True);
        }
Beispiel #28
0
        public void CalculateDistanceBetweenPoints(double x1, double y1, double x2, double y2)
        {
            //https://nettopologysuite.github.io/html/class_net_topology_suite_1_1_operation_1_1_distance_1_1_distance_op.html
            var point1 = new NetTopologySuite.Geometries.Point(x1, y1)
            {
                SRID = srid
            };
            var point2 = new NetTopologySuite.Geometries.Point(x2, y2)
            {
                SRID = srid
            };
            var distance = NetTopologySuite.Operation.Distance.DistanceOp.Distance(point1, point2);

            Console.WriteLine($"点({x1},{y1})和点({x2},{y2})的距离是{distance}.");
        }
Beispiel #29
0
        public static void DrawPoint(Graphics g, Point point, Brush b, float size, PointF offset, MapViewport map)
        {
            if (point == null)
            {
                return;
            }

            var pp = map.WorldToImage(point.Coordinate);
            //var startingTransform = g.Transform;

            var width  = size;
            var height = size;

            g.FillEllipse(b, (int)pp.X - width / 2 + offset.X,
                          (int)pp.Y - height / 2 + offset.Y, width, height);
        }
        /// <summary>
        /// Calculate the center point of the airport
        /// The DAT data should give us an airport boundary which will be an irregular polygon
        /// If this is present, we work out the center of its bounding box
        /// If this isn't present we just get the end of a runway
        /// </summary>
        /// <returns></returns>
        private GeoCoordinate CalculateAirportCenterPoint()
        {
            GeoCoordinate centerPoint = new GeoCoordinate();

            if (this.datFile.AirportBoundary != null && this.datFile.AirportBoundary.Nodes != null && this.datFile.AirportBoundary.Nodes.Count > 0)
            {
                GeometryFactory geometryFactory = new GeometryFactory();
                List <Geometry> geometries      = new List <Geometry>();

                foreach (var node in this.datFile.AirportBoundary.Nodes)
                {
                    Coordinate coord = new Coordinate(node.Longitude, node.Latitude);
                    NetTopologySuite.Geometries.Point geometry = (NetTopologySuite.Geometries.Point)geometryFactory.CreatePoint(coord);
                    geometries.Add(geometry);
                }

                GeometryCollection geometryCollection = new GeometryCollection(geometries.ToArray());
                var boundingBox = geometryCollection.Envelope;
                centerPoint.Longitude = boundingBox.Centroid.Coordinate.X;
                centerPoint.Latitude  = boundingBox.Centroid.Coordinate.Y;
            }
            else
            {
                // As a plan B get the center of the first or only runway
                // TODO - use the center point of a runway if we don't have a bounding box
                if (this.datFile.Helipad != null)
                {
                    centerPoint.Latitude  = this.datFile.Helipad.Latitude;
                    centerPoint.Longitude = this.datFile.Helipad.Longitude;
                }

                if (this.datFile.WaterRunways != null && this.datFile.WaterRunways.Count > 0)
                {
                    centerPoint.Latitude  = this.datFile.WaterRunways[0].End1.Latitude;
                    centerPoint.Longitude = this.datFile.WaterRunways[0].End1.Longitude;
                }

                if (this.datFile.LandRunways != null && this.datFile.LandRunways.Count > 0)
                {
                    centerPoint.Latitude  = this.datFile.LandRunways[0].End1.Latitude;
                    centerPoint.Longitude = this.datFile.LandRunways[0].End1.Longitude;
                }
            }

            //log.DebugFormat("{0} {1}", centerPoint.Latitude, centerPoint.Longitude);
            return(centerPoint);
        }
Beispiel #31
0
 private NetTopologySuite.Geometries.Geometry KmlGeometryToGeometry(SharpKml.Dom.Geometry geometry)
 {
     NetTopologySuite.Geometries.Geometry result = null;
     if (geometry is SharpKml.Dom.Point)
     {
         var kmlPoint = geometry as SharpKml.Dom.Point;
         result = new NetTopologySuite.Geometries.Point(new Coordinate(kmlPoint.Coordinate.Longitude, kmlPoint.Coordinate.Latitude));
     }
     else if (geometry is SharpKml.Dom.Polygon)
     {
         var kmlPolygon = geometry as SharpKml.Dom.Polygon;
         if (kmlPolygon.OuterBoundary == null || kmlPolygon.OuterBoundary.LinearRing == null || kmlPolygon.OuterBoundary.LinearRing.Coordinates == null)
         {
             throw new Exception("Polygon is null");
         }
         var coordinates = new Coordinate[kmlPolygon.OuterBoundary.LinearRing.Coordinates.Count];
         int i           = 0;
         foreach (var coordinate in kmlPolygon.OuterBoundary.LinearRing.Coordinates)
         {
             coordinates[i++] = new Coordinate(coordinate.Longitude, coordinate.Latitude);
         }
         result = new NetTopologySuite.Geometries.Polygon(new NetTopologySuite.Geometries.LinearRing(coordinates));
     }
     else if (geometry is SharpKml.Dom.MultipleGeometry)
     {
         var mgeometry = geometry as SharpKml.Dom.MultipleGeometry;
         var polygons  = new List <NetTopologySuite.Geometries.Polygon>();
         foreach (var poly in mgeometry.Geometry)
         {
             var kmlPolygon = poly as SharpKml.Dom.Polygon;
             if (kmlPolygon.OuterBoundary == null || kmlPolygon.OuterBoundary.LinearRing == null || kmlPolygon.OuterBoundary.LinearRing.Coordinates == null)
             {
                 throw new Exception("Polygon is null");
             }
             var coordinates = new Coordinate[kmlPolygon.OuterBoundary.LinearRing.Coordinates.Count];
             int i           = 0;
             foreach (var coordinate in kmlPolygon.OuterBoundary.LinearRing.Coordinates)
             {
                 coordinates[i++] = new Coordinate(coordinate.Longitude, coordinate.Latitude);
             }
             polygons.Add(new NetTopologySuite.Geometries.Polygon(new NetTopologySuite.Geometries.LinearRing(coordinates)));
         }
         result = new NetTopologySuite.Geometries.MultiPolygon(polygons.ToArray());
     }
     return(result);
 }
        public void AddObject(string name, Point startAt)
        {
            lock (((ICollection)_movingObjects).SyncRoot)
            {
                var fp  = (GeometryFeatureProvider)_lyr.DataSource;
                var fdr = fp.Features.NewRow();
                fdr[1]       = name;
                fdr[2]       = 0;
                fdr[3]       = _scale;
                fdr[4]       = _color.ToArgb();
                fdr.Geometry = startAt;
                fp.Features.AddRow(fdr);
                fp.Features.AcceptChanges();

                var obj = new MovingObject(Convert.ToUInt32(fdr[0]), startAt);
                _movingObjects.Add(obj);
            }
        }
Beispiel #33
0
        private void miSaveGeo_Click(object sender, EventArgs e)
        {
            string fileName = Path.Combine(Constants.DATA_DIR, "beijingTrjPart",
                                           "stat", "parkingRegion.txt");
            StreamWriter sw = new StreamWriter(fileName);

            foreach (var geo in outputProvider.Geometries)
            {
                List <string> points = new List <string>();
                foreach (var coor in geo.Coordinates)
                {
                    Point point = (Point)GeometryTransform.TransformGeometry(new Point(coor),
                                                                             LayerTools.GoogleMercatorToWgs84.MathTransform, geofactory);
                    points.Add(string.Format("{0},{1}", point.Y, point.X));
                }
                sw.WriteLine(String.Join(",", points.ToArray()));
            }
            sw.Close();
        }
Beispiel #34
0
        public MapLifeLine(Individual ind)
        {
            this.ind = ind;
            int index = 1;
            List <Coordinate> points = new List <Coordinate>();

            this.viewport = new Envelope();
            Coordinate previousPoint = null;

            foreach (IDisplayFact f in ind.AllGeocodedFacts)
            {
                Coordinate point = new Coordinate(f.Location.LongitudeM, f.Location.LatitudeM);
                if (index == 1)
                {
                    StartPoint = new NetTopologySuite.Geometries.Point(point);
                }
                if (index == ind.AllGeocodedFacts.Count)
                {
                    EndPoint = new NetTopologySuite.Geometries.Point(point);
                }
                index++;
                if (points.Count == 0 || (points.Count > 0 && !point.Equals2D(previousPoint)))
                {
                    points.Add(point); // don't add point if same as last one
                    previousPoint = point;
                }
                GeoResponse.CResult.CGeometry.CViewPort vp = f.Location.ViewPort;
                Envelope env = new Envelope(vp.NorthEast.Long, vp.SouthWest.Long, vp.NorthEast.Lat, vp.SouthWest.Lat);
                if (!viewport.Contains(env))
                {
                    viewport.ExpandToInclude(env);
                }
            }
            if (points.Count > 1)
            {
                this.Geometry = new NetTopologySuite.Geometries.LineString(points.ToArray());
            }
            else
            {
                this.Geometry = StartPoint;
            }
            Count = points.Count;
        }
        public void AddObject(string name, Point startAt)
        {
            lock (((ICollection)_movingObjects).SyncRoot)
            {
                var   fp      = (GeometryFeatureProvider)_lyr.DataSource;
                var   fdr     = fp.Features.NewRow();
                float heading = (float)Rnd.Next(0, 359);
                fdr[1]       = name;
                fdr[2]       = MovingObject.NormalizePositive(90f - heading);
                fdr[3]       = _scale;
                fdr[4]       = _color.ToArgb();
                fdr.Geometry = startAt;
                fp.Features.AddRow(fdr);
                fp.Features.AcceptChanges();

                var obj = new MovingObject(Convert.ToUInt32(fdr[0]), startAt, heading);
                _movingObjects.Add(obj);
            }
        }
Beispiel #36
0
  private void GetMidpoint(ILineString lineString, out IPoint midPoint, out double angle)
  {
    midPoint = null;
    angle = Double.NaN;

    double lineStringLength = lineString.Length;

    if (lineStringLength == 0)
    {
      return;
    }

    double halfLength = lineStringLength * 0.5;

    for (int i = 0; i < lineString.Coordinates.Length - 1; ++i)
    {
      Coordinate p0 = lineString.Coordinates[i];
      Coordinate p1 = lineString.Coordinates[i + 1];

      double dx = p1.X - p0.X;
      double dy = p1.Y - p0.Y;

      double segmentLength = Math.Sqrt(dx * dx + dy * dy);

      if (halfLength <= segmentLength)
      {
        double ratio = halfLength / segmentLength;
        midPoint = new NetTopologySuite.Geometries.Point(p0.X + ratio * dx, p0.Y + ratio * dy);
        angle = Math.Atan2(dy, dx);
        break;
      }
      else
      {
        halfLength -= segmentLength;
      }
    }
  }
Beispiel #37
0
        private void drawPoint(NTSPoint ge, Graphics gr, Style c)
        {
            float rad = Math.Max(1, c.pen.Width * 5 * (float)scale.X);
            var mid = ScaleAndOffSet(ge);

            gr.FillEllipse(c.brush, (int)(mid.X - rad), (int)(mid.Y - rad), (int)(rad*2), (int)(rad*2));
        }
 private static bool IsSameStructurePoint(Point g1, Point g2)
 {
     // could check for both empty or nonempty here
     return true;
 }
Beispiel #39
0
 // constructor clones objects so they are not changed in other threads
 public Render(NTSPoint s, NTSPoint o)
 {
     offset = (NTSPoint) o.Clone();
     scale = (NTSPoint)s.Clone();
 }
Beispiel #40
0
 // transforms real world point to screen point
 public NTSPoint MapRealToScreen(NTSPoint pt)
 {
     return new NTSPoint(((pt.X - offset.X) * scale.X),
                         ((pt.Y - offset.Y) * scale.Y));
 }
Beispiel #41
0
 public Point ViewToWorld(Point point)
 {
     return new NetTopologySuite.Geometries.Point((extent.MinX + point.X * resolution), (extent.MaxY - (point.Y * resolution)));
 }
Beispiel #42
0
 public Point WorldToView(Point point)
 {
     return new NetTopologySuite.Geometries.Point((point.X - extent.MinX) / resolution, (extent.MaxY - point.Y) / resolution);
 }
Beispiel #43
0
        public static Point Create(double latitude, double longitude)
        {
            var point = new Point(longitude, latitude) { SRID = WorldGeodeticSystemSrid };

            return point;
        }
 public void gml_reader_can_read_ToGMLFeature()
 {
     GMLReader reader = new GMLReader();
     Point geom = new Point(52, -0.9);
     IGeometry actual = reader.Read(geom.ToGMLFeature());
     Assert.That(actual, Is.Not.Null);
     Assert.That(actual.EqualsExact(geom), Is.True);
 }