Пример #1
0
        private static IGeometry CreateJ(IGeometry g)
        {
            var gf = FunctionsUtil.GetFactoryOrDefault(g);

            var jTop = new Coordinate[]
                           {
                               new Coordinate(0, HEIGHT),
                               new Coordinate(J_WIDTH, HEIGHT),
                               new Coordinate(J_WIDTH, J_RADIUS)
                           };
            var jBottom = new Coordinate[]
                              {
                                  new Coordinate(J_WIDTH - J_RADIUS, 0),
                                  new Coordinate(0, 0)
                              };

            var gsf = new GeometricShapeFactory(gf);
            gsf.Base = new Coordinate(J_WIDTH - 2 * J_RADIUS, 0);
            gsf.Size = 2 * J_RADIUS;
            gsf.NumPoints = 10;
            var jArc = gsf.CreateArc(1.5 * Math.PI, 0.5 * Math.PI);

            var coordList = new CoordinateList();
            coordList.Add(jTop, false);
            coordList.Add(((IGeometry)jArc).Reverse().Coordinates, false, 1, jArc.NumPoints - 1);
            coordList.Add(jBottom, false);

            return gf.CreateLineString(coordList.ToCoordinateArray());
        }
 static IGeometry CreateTestCircle(Coordinate origin, double size, int nPts)
 {
     GeometricShapeFactory gsf = new GeometricShapeFactory();
     gsf.Centre = origin;
     gsf.Size = size;
     gsf.NumPoints = nPts;
     IGeometry circle = gsf.CreateCircle();
     //    System.out.println(circle);
     return circle;
 }
  public IGeometry CreateLine(Coordinate @base, double size, int nPts)
  {
    var gsf = new GeometricShapeFactory();
    gsf.Centre = _origin;
    gsf.Size = size;
    gsf.NumPoints = nPts;
    var circle = gsf.CreateCircle();
//    System.out.println(circle);
    return circle.Boundary;
  }
	public IGeometry CreateCircle(int nPts) {
		var gsf = new GeometricShapeFactory(_geomFact);
		gsf.Centre = _origin;
		gsf.Size = _size;
		gsf.NumPoints = nPts;
		var circle = gsf.CreateCircle();
		// var gRect = gsf.CreateRectangle();
		// var g = gRect.ExteriorRing);
		return circle;
	}
 static ILineString CreateTestLine(Coordinate basePt, double size, int nPts)
 {
     GeometricShapeFactory gsf = new GeometricShapeFactory();
     gsf.Centre = basePt;
     gsf.Size = size;
     gsf.NumPoints = nPts;
     IGeometry circle = gsf.CreateCircle();
     //    System.out.println(circle);
     return (ILineString)circle.Boundary;
 }
 static IGeometry CreateCircle(Coordinate origin, double size, int nPts)
 {
     GeometricShapeFactory gsf = new GeometricShapeFactory();
     gsf.Centre = origin;
     gsf.Size = size;
     gsf.NumPoints = nPts;
     IGeometry circle = gsf.CreateCircle();
     // Polygon gRect = gsf.createRectangle();
     // Geometry g = gRect.getExteriorRing();
     return circle;
 }
Пример #7
0
        /**
         * Gets a JTS {@link Geometry} for the given {@link Shape}. Some shapes hold a
         * JTS geometry whereas new ones must be created for the rest.
         * @param shape Not null
         * @return Not null
         */
        public IGeometry GetGeometryFrom(Shape shape)
        {
            if (shape is NtsGeometry)
            {
                return ((NtsGeometry)shape).GetGeom();
            }
            if (shape is NtsPoint)
            {
                return ((NtsPoint)shape).GetGeom();
            }

            var point = shape as Shapes.Point;
            if (point != null)
            {
                return geometryFactory.CreatePoint(new Coordinate(point.GetX(), point.GetY()));
            }

            var r = shape as Rectangle;
            if (r != null)
            {

                if (r.GetCrossesDateLine())
                {
                    var pair = new List<IGeometry>(2)
                   	{
                   		geometryFactory.ToGeometry(new Envelope(
                   		                           	r.GetMinX(), GetWorldBounds().GetMaxX(), r.GetMinY(), r.GetMaxY())),
                   		geometryFactory.ToGeometry(new Envelope(
                   		                           	GetWorldBounds().GetMinX(), r.GetMaxX(), r.GetMinY(), r.GetMaxY()))
                   	};
                    return geometryFactory.BuildGeometry(pair);//a MultiPolygon or MultiLineString
                }
                else
                {
                    return geometryFactory.ToGeometry(new Envelope(r.GetMinX(), r.GetMaxX(), r.GetMinY(), r.GetMaxY()));
                }
            }

            var circle = shape as Circle;
            if (circle != null)
            {
                // TODO, this should maybe pick a bunch of points
                // and make a circle like:
                //  http://docs.codehaus.org/display/GEOTDOC/01+How+to+Create+a+Geometry#01HowtoCreateaGeometry-CreatingaCircle
                // If this crosses the dateline, it could make two parts
                // is there an existing utility that does this?

                if (circle.GetBoundingBox().GetCrossesDateLine())
                    throw new ArgumentException("Doesn't support dateline cross yet: " + circle);//TODO
                var gsf = new GeometricShapeFactory(geometryFactory)
                            {
                                Size = circle.GetBoundingBox().GetWidth() / 2.0f,
                                NumPoints = 4 * 25,//multiple of 4 is best
                                Base = new Coordinate(circle.GetCenter().GetX(), circle.GetCenter().GetY())
                            };
                return gsf.CreateCircle();
            }
            throw new InvalidShapeException("can't make Geometry from: " + shape);
        }
 public static IGeometry Supercircle(IGeometry g, int nPts, double pow)
 {
     var gsf = new GeometricShapeFactory();
     gsf.NumPoints = nPts;
     if (g != null)
         gsf.Envelope = g.EnvelopeInternal;
     else
         gsf.Envelope = new Envelope(0, 1, 0, 1);
     return gsf.CreateSupercircle(pow);
 }
 public void TestBigPolygon()
 {
     GeometricShapeFactory shapeFactory = new GeometricShapeFactory(GeomFactory);
     shapeFactory.Base = new Coordinate(0, 0);
     shapeFactory.Size = 1000;
     shapeFactory.NumPoints = 1000;
     IGeometry geom = shapeFactory.CreateRectangle();
     RunWKBTest(geom, 2, false);
 }
Пример #10
0
        private static IGeometry CreateS(IGeometry g)
        {
            var gf = FunctionsUtil.GetFactoryOrDefault(g);

            double centreX = WIDTH - S_RADIUS;

            var top = new[]
                          {
                              new Coordinate(WIDTH, HEIGHT),
                              new Coordinate(centreX, HEIGHT)
                          };
            var bottom = new[]
                             {
                                 new Coordinate(centreX, 0),
                                 new Coordinate(WIDTH - 2*S_RADIUS, 0)
                             };

            var gsf = new GeometricShapeFactory(gf);
            gsf.Centre = new Coordinate(centreX, HEIGHT - S_RADIUS);
            gsf.Size = 2 * S_RADIUS;
            gsf.NumPoints = 10;
            var arcTop = gsf.CreateArc(0.5 * Math.PI, Math.PI);

            var gsf2 = new GeometricShapeFactory(gf);
            gsf2.Centre = new Coordinate(centreX, S_RADIUS);
            gsf2.Size = 2 * S_RADIUS;
            gsf2.NumPoints = 10;
            var arcBottom = (ILineString)((IGeometry)gsf2.CreateArc(1.5 * Math.PI, Math.PI)).Reverse();

            var coordList = new CoordinateList();
            coordList.Add(top, false);
            coordList.Add(arcTop.Coordinates, false, 1, arcTop.NumPoints - 1);
            coordList.Add(new Coordinate(centreX, HEIGHT / 2));
            coordList.Add(arcBottom.Coordinates, false, 1, arcBottom.NumPoints - 1);
            coordList.Add(bottom, false);

            return gf.CreateLineString(coordList.ToCoordinateArray());
        }
Пример #11
0
        // returns closest feature to real-world coordinate
        // return null if no features within limit
        public Feature getClosest(Point p, double limit)
        {
            GeometricShapeFactory gsf = new GeometricShapeFactory();
            gsf.Envelope = new Envelope(p.X - limit, p.X + limit, p.Y - limit, p.Y + limit);
            IGeometry circle = gsf.CreateCircle();
            var candidates = getWithin(circle);

            double min = 0;
            Feature minf = null;
            foreach (var f in candidates)
            {
                double dist = f.Geometry.Distance(p);
                if (minf == null || dist < min)
                {
                    minf = f;
                    min = dist;
                }
            }
            return minf;
        }