Esempio n. 1
0
 private IEnumerable <IFeature> EnumerateFeatures(IPreparedGeometry preparedGeometry)
 {
     lock (_featuresLock)
     {
         uint id = 0;
         if (FilterDelegate == null)
         {
             foreach (var feature in _features)
             {
                 var geom = feature.Geometry;
                 if (preparedGeometry.Intersects(feature.Geometry))
                 {
                     yield return(feature);
                 }
                 id++;
             }
         }
         else
         {
             foreach (var feature in _features)
             {
                 if (FilterDelegate(feature) && preparedGeometry.Intersects(feature.Geometry))
                 {
                     yield return(feature);
                 }
                 id++;
             }
         }
     }
 }
Esempio n. 2
0
 protected virtual SpatialRelation Relate(IGeometry oGeom)
 {
     //see http://docs.geotools.org/latest/userguide/library/jts/dim9.html#preparedgeometry
     if (oGeom is GeoAPI.Geometries.IPoint) // TODO: This may not be the correct data type....
     {
         if (preparedGeometry != null)
         {
             return(preparedGeometry.Disjoint(oGeom) ? SpatialRelation.DISJOINT : SpatialRelation.CONTAINS);
         }
         return(geom.Disjoint(oGeom) ? SpatialRelation.DISJOINT : SpatialRelation.CONTAINS);
     }
     if (preparedGeometry == null)
     {
         return(IntersectionMatrixToSpatialRelation(geom.Relate(oGeom)));
     }
     else if (preparedGeometry.Covers(oGeom))
     {
         return(SpatialRelation.CONTAINS);
     }
     else if (preparedGeometry.CoveredBy(oGeom))
     {
         return(SpatialRelation.WITHIN);
     }
     else if (preparedGeometry.Intersects(oGeom))
     {
         return(SpatialRelation.INTERSECTS);
     }
     return(SpatialRelation.DISJOINT);
 }
Esempio n. 3
0
        public static List <IFeature> GetFeatureCollectionFromGeoJsonByteArray(byte[] fileContentsByteArray,
                                                                               int coordinatePrecision, IPreparedGeometry boundingBox)
        {
            var featureCollection = GetFeatureCollectionFromGeoJsonByteArray(fileContentsByteArray, coordinatePrecision);

            return(featureCollection.Where(x => boundingBox.Intersects(x.Geometry)).ToList());
        }
Esempio n. 4
0
        /// <summary>
        /// Determine if a Polygon (presumably from a map element) intersects with the data contained in the server.
        /// </summary>
        /// <param name="bounds">PreparedGeometry representing the server's usable boundaries</param>
        /// <param name="place">Polygon to check against the server's bounds</param>
        /// <returns>true if the 2 parameters intersect, or false if they do not.</returns>
        public static bool IsInBounds(IPreparedGeometry bounds, Polygon place)
        {
            if (DisableBoundsCheck || bounds.Intersects(place))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 5
0
        /// <summary>
        /// Determine if a GeoArea (presumably from a PlusCode) intersects with the data contained in the server.
        /// </summary>
        /// <param name="bounds">PreparedGeometry representing the server's usable boundaries</param>
        /// <param name="place">GeoArea to check against the server's bounds</param>
        /// <returns>true if the 2 parameters intersect, or false if they do not.</returns>
        public static bool IsInBounds(IPreparedGeometry bounds, GeoArea place)
        {
            if (DisableBoundsCheck || bounds.Intersects(Converters.GeoAreaToPolygon(place)))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 6
0
        /// <summary>
        /// Determine if a Lat/Lon coordinate pair intersects with the data contained in the server.
        /// </summary>
        /// <param name="bounds">PreparedGeometry representing the server's usable boundaries</param>
        /// <param name="lat">latitude in degrees</param>
        /// <param name="lon">longitude in degrees</param>
        /// <returns>true if the 2 parameters intersect, or false if they do not.</returns>
        public static bool IsInBounds(IPreparedGeometry bounds, double lat, double lon)
        {
            Point p = new Point(lon, lat);

            if (DisableBoundsCheck || bounds.Intersects(p))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 7
0
        private static void CheckIntersects(IPreparedGeometry pg, IGeometry g2)
        {
            bool pgResult = pg.Intersects(g2);
            bool expected = pg.Geometry.Intersects(g2);

            if (pgResult != expected)
            {
                // pg.intersects(g2);
                throw new InvalidOperationException("PreparedGeometry.intersects result does not match expected");
            }

            // System.out.println("Results match!");
        }
        private static void CheckIntersects(IPreparedGeometry pg, IGeometry g2)
        {
            bool pgResult = pg.Intersects(g2);
            bool expected = pg.Geometry.Intersects(g2);

            if (pgResult != expected)
            {
                //			pg.intersects(g2);
                throw new InvalidOperationException("PreparedGeometry.intersects result does not match expected");
            }

            //		System.out.println("Results match!");
        }
        private bool CheckIfMatch(IPreparedGeometry polygon, Geometry current_polygon, Mode mode)
        {
            if (mode == Mode.Intersect)
            {
                return(polygon.Intersects(current_polygon));
            }

            if (mode == Mode.Contains)
            {
                return(polygon.Contains(current_polygon));
            }

            throw new InvalidEnumArgumentException("unkown mode");
        }
            private static Boolean CheckIntersects(IGeometry target, IGeometry test)
            {
                bool expectedResult = target.Intersects(test);

                PreparedGeometryFactory pgFact   = new PreparedGeometryFactory();
                IPreparedGeometry       prepGeom = pgFact.Create(target);

                bool prepResult = prepGeom.Intersects(test);

                if (prepResult != expectedResult)
                {
                    return(false);
                }
                return(true);
            }
        public void TestResultsEqual(IGeometry g, ILineString line)
        {
            bool slowIntersects = g.Intersects(line);

            PreparedGeometryFactory pgFact   = new PreparedGeometryFactory();
            IPreparedGeometry       prepGeom = pgFact.Create(g);

            bool fastIntersects = prepGeom.Intersects(line);

            if (slowIntersects != fastIntersects)
            {
                Console.WriteLine(line);
                Console.WriteLine("Slow = " + slowIntersects + ", Fast = " + fastIntersects);
                throw new Exception("Different results found for intersects() !");
            }
        }
Esempio n. 12
0
        private void AddParishNames(List <Feature> features, string fieldname)
        {
            int featureNum       = 0;
            int originalToSearch = 0;
            int lastSaved        = int.MaxValue;
            int featuresCount    = features.Count();

            foreach (Feature f in features)
            {
                featureNum++;
                if (f.Attributes[fieldname] == null || f.Attributes[fieldname].ToString().Length == 0)
                {
                    Console.WriteLine("Parish is null?? type_code:" + f.Attributes["TYPE_CODE"]); // f.Attributes["TYPE_CODE"] = "FA"
                }
                IPreparedGeometry geom = PreparedGeometryFactory.Prepare(f.Geometry);
                int count = 0;
                IEnumerable <OS50kGazetteer> toSearch = OS50k.Where(x => x.ParishName == null || x.ParishName.Length == 0);
                if (originalToSearch == 0)
                {
                    originalToSearch = toSearch.Count();
                }
                foreach (OS50kGazetteer os50k in toSearch)
                {
                    if (geom.Intersects(os50k.BufferedPoint))
                    {
                        os50k.ParishName = (string)f.Attributes[fieldname];
                        if (os50k.ParishName.EndsWith(" CP"))
                        {
                            os50k.ParishName = os50k.ParishName.Substring(0, os50k.ParishName.Length - 3);
                        }
                        count++;
                    }
                }
                int left = toSearch.Count() - count;
                textBox1.AppendText("Set " + count + " entries for parish: " + f.Attributes[fieldname] + " number " + featureNum + " / " + featuresCount + " leaving " + left + " of " + originalToSearch + " to search\n");
                if (lastSaved - 2000 > left)
                {
                    lastSaved = left;
                    SaveOS50kGazetteer();
                }
                Application.DoEvents();
            }
        }