Пример #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testBuildGeometryFromValidPolygon()
        public virtual void testBuildGeometryFromValidPolygon()
        {
            string testfile = "valid-polygon.wkt";

            IList <TDWay> ways     = MockingUtils.wktPolygonToWays(testfile);
            Geometry      geometry = JTSUtils.toJtsGeometry(ways[0], ways.subList(1, ways.Count));

            Assert.isTrue(geometry is LineString);
            Assert.isTrue(geometry.Valid);
        }
Пример #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testBuildInValidPolygonWith2InnerRings()
        public virtual void testBuildInValidPolygonWith2InnerRings()
        {
            string testfile = "invalid-polygon-2-inner-rings.wkt";

            IList <TDWay> ways     = MockingUtils.wktPolygonToWays(testfile);
            Polygon       polygon  = JTSUtils.buildPolygon(ways[0], ways.subList(1, ways.Count));
            Geometry      expected = MockingUtils.readWKTFile(testfile);

            Assert.isTrue(!polygon.Valid);
            Assert.Equals(expected, polygon);
        }
Пример #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testBuildInvalidPolygon()
        public virtual void testBuildInvalidPolygon()
        {
            string testfile = "invalid-polygon.wkt";

            IList <TDWay> ways     = MockingUtils.wktPolygonToWays(testfile);
            Polygon       polygon  = JTSUtils.buildPolygon(ways[0]);
            Geometry      expected = MockingUtils.readWKTFile(testfile);

            Assert.isTrue(!polygon.Valid);
            Assert.Equals(expected, polygon);
        }
Пример #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testBuildValidMultiLineString()
        public virtual void testBuildValidMultiLineString()
        {
            string testfile = "valid-multilinestring.wkt";

            IList <TDWay>   ways     = MockingUtils.wktMultiLineStringToWays(testfile);
            MultiLineString mls      = JTSUtils.buildMultiLineString(ways[0], ways.subList(1, ways.Count));
            Geometry        expected = MockingUtils.readWKTFile(testfile);

            Assert.isTrue(mls.Valid);
            Assert.Equals(expected, mls);
        }
Пример #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testBuildGeometryFromInValidPolygon()
        public virtual void testBuildGeometryFromInValidPolygon()
        {
            // Some of these tests do not really make sense, as not everything that is a closed line
            // should be a polygon in OSM.
            string testfile = "invalid-polygon.wkt";
            // String expectedfile = "invalid-polygon-repaired.wkt";

            IList <TDWay> ways     = MockingUtils.wktPolygonToWays(testfile);
            Geometry      geometry = JTSUtils.toJtsGeometry(ways[0], ways.subList(1, ways.Count));

            Assert.isTrue(geometry is LineString);
            Assert.isTrue(geometry.Valid);
        }
Пример #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testBuildGeometryFromInValidPolygonWithHoles()
        public virtual void testBuildGeometryFromInValidPolygonWithHoles()
        {
            string testfile     = "invalid-polygon-2-inner-rings.wkt";
            string expectedfile = "invalid-polygon-2-inner-rings-repaired.wkt";

            IList <TDWay> ways     = MockingUtils.wktPolygonToWays(testfile);
            Geometry      geometry = JTSUtils.toJtsGeometry(ways[0], ways.subList(1, ways.Count));

            Assert.isTrue(geometry is Polygon);
            Assert.isTrue(geometry.Valid);

            Geometry expected = MockingUtils.readWKTFile(expectedfile);

            Assert.Equals(expected, geometry);
        }
Пример #7
0
        /// <summary>
        /// Clips a geometry to a tile.
        /// </summary>
        /// <param name="way">
        ///            the way </param>
        /// <param name="geometry">
        ///            the geometry </param>
        /// <param name="tileCoordinate">
        ///            the tile coordinate </param>
        /// <param name="enlargementInMeters">
        ///            the bounding box buffer </param>
        /// <returns> the clipped geometry </returns>
        public static Geometry clipToTile(TDWay way, Geometry geometry, TileCoordinate tileCoordinate, int enlargementInMeters)
        {
            Geometry tileBBJTS = null;
            Geometry ret       = null;

            // create tile bounding box
            tileBBJTS = tileToJTSGeometry(tileCoordinate.X, tileCoordinate.Y, tileCoordinate.Zoomlevel, enlargementInMeters);

            // clip the geometry by intersection with the bounding box of the tile
            // may throw a TopologyException
            try
            {
                if (!geometry.Valid)
                {
                    // this should stop the problem of non-noded intersections that trigger an error when
                    // clipping
                    LOGGER.warning("invalid geometry prior to tile clipping, trying to repair " + way.Id);
                    geometry = JTSUtils.repairInvalidPolygon(geometry);
                    if (!geometry.Valid)
                    {
                        LOGGER.warning("invalid geometry even after attempt to fix " + way.Id);
                    }
                }
                ret = tileBBJTS.intersection(geometry);
                // according to Ludwig (see issue332) valid polygons may become invalid by clipping (at least
                // in the Python shapely library
                // we need to investigate this more closely and write approriate test cases
                // for now, I check whether the resulting polygon is valid and if not try to repair it
                if ((ret is Polygon || ret is MultiPolygon) && !ret.Valid)
                {
                    LOGGER.warning("clipped way is not valid, trying to repair it: " + way.Id);
                    ret = JTSUtils.repairInvalidPolygon(ret);
                    if (ret == null)
                    {
                        way.Invalid = true;
                        LOGGER.warning("could not repair invalid polygon: " + way.Id);
                    }
                }
            }
            catch (TopologyException e)
            {
                LOGGER.log(Level.WARNING, "JTS cannot clip way, not storing it in data file: " + way.Id, e);
                way.Invalid = true;
                return(null);
            }
            return(ret);
        }
Пример #8
0
        // **************** WAY OR POI IN TILE *****************
        /// <summary>
        /// Computes which tiles on the given base zoom level need to include the given way (which may be a polygon).
        /// </summary>
        /// <param name="way">
        ///            the way that is mapped to tiles </param>
        /// <param name="baseZoomLevel">
        ///            the base zoom level which is used in the mapping </param>
        /// <param name="enlargementInMeter">
        ///            amount of pixels that is used to enlarge the bounding box of the way and the tiles in the mapping
        ///            process </param>
        /// <returns> all tiles on the given base zoom level that need to include the given way, an empty set if no tiles are
        ///         matched </returns>
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: public static java.util.Set<org.mapsforge.map.writer.model.TileCoordinate> mapWayToTiles(final org.mapsforge.map.writer.model.TDWay way, final byte baseZoomLevel, final int enlargementInMeter)
        public static ISet <TileCoordinate> mapWayToTiles(TDWay way, sbyte baseZoomLevel, int enlargementInMeter)
        {
            if (way == null)
            {
                LOGGER.fine("way is null in mapping to tiles");
                return(Collections.emptySet());
            }

            HashSet <TileCoordinate> matchedTiles = new HashSet <TileCoordinate>();
            Geometry wayGeometry = JTSUtils.toJTSGeometry(way);

            if (wayGeometry == null)
            {
                way.Invalid = true;
                LOGGER.fine("unable to create geometry from way: " + way.Id);
                return(matchedTiles);
            }

            TileCoordinate[] bbox = getWayBoundingBox(way, baseZoomLevel, enlargementInMeter);
            // calculate the tile coordinates and the corresponding bounding boxes
            try
            {
                for (int k = bbox[0].X; k <= bbox[1].X; k++)
                {
                    for (int l = bbox[0].Y; l <= bbox[1].Y; l++)
                    {
                        Geometry bboxGeometry = tileToJTSGeometry(k, l, baseZoomLevel, enlargementInMeter);
                        if (bboxGeometry.intersects(wayGeometry))
                        {
                            matchedTiles.Add(new TileCoordinate(k, l, baseZoomLevel));
                        }
                    }
                }
            }
            catch (TopologyException)
            {
                LOGGER.fine("encountered error during mapping of a way to corresponding tiles, way id: " + way.Id);
                return(Collections.emptySet());
            }

            return(matchedTiles);
        }
Пример #9
0
 internal static Polygon buildPolygon(TDWay way)
 {
     Coordinate[] coordinates = JTSUtils.toCoordinates(way);
     return(GEOMETRY_FACTORY.createPolygon(GEOMETRY_FACTORY.createLinearRing(coordinates), null));
 }
Пример #10
0
 internal static LineString buildLineString(TDWay way)
 {
     Coordinate[] coordinates = JTSUtils.toCoordinates(way);
     return(GEOMETRY_FACTORY.createLineString(coordinates));
 }