org.json.simple.JSONAware#com.vividsolutions.jts.geom.Point源码实例Demo

下面列出了org.json.simple.JSONAware#com.vividsolutions.jts.geom.Point 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: sldeditor   文件: AllowedAttributeTypes.java
/**
 * Initialise.
 */
private static void initialise()
{
    List<Class<?> > doubleList = new ArrayList<Class<?> >(Arrays.asList(Integer.class, Long.class, Double.class, Float.class));
    List<Class<?> > integerList = new ArrayList<Class<?> >(Arrays.asList(Integer.class, Long.class));
    List<Class<?> > stringList = new ArrayList<Class<?> >(Arrays.asList(String.class));
    List<Class<?> > geometryList = new ArrayList<Class<?> >(Arrays.asList(Point.class, LineString.class, Polygon.class, MultiPolygon.class, MultiPoint.class, MultiLineString.class));

    allowedClassTypeMap.put(String.class, stringList);
    allowedClassTypeMap.put(Double.class, doubleList);
    allowedClassTypeMap.put(Float.class, doubleList);
    allowedClassTypeMap.put(Integer.class, integerList);
    allowedClassTypeMap.put(Long.class, integerList);
    allowedClassTypeMap.put(Geometry.class, geometryList);

    List<Class<?> > objectList = new ArrayList<Class<?>>();
    objectList.addAll(doubleList);
    objectList.addAll(integerList);
    objectList.addAll(stringList);
    objectList.addAll(geometryList);
    allowedClassTypeMap.put(Object.class, objectList);
}
 
源代码2 项目: jts   文件: WKBWriter.java
/**
 * Writes a {@link Geometry} to an {@link OutStream}.
 *
 * @param geom the geometry to write
 * @param os the out stream to write to
 * @throws IOException if an I/O error occurs
 */
public void write(Geometry geom, OutStream os) throws IOException
{
  if (geom instanceof Point)
    writePoint((Point) geom, os);
  // LinearRings will be written as LineStrings
  else if (geom instanceof LineString)
    writeLineString((LineString) geom, os);
  else if (geom instanceof Polygon)
    writePolygon((Polygon) geom, os);
  else if (geom instanceof MultiPoint)
    writeGeometryCollection(WKBConstants.wkbMultiPoint, 
        (MultiPoint) geom, os);
  else if (geom instanceof MultiLineString)
    writeGeometryCollection(WKBConstants.wkbMultiLineString,
        (MultiLineString) geom, os);
  else if (geom instanceof MultiPolygon)
    writeGeometryCollection(WKBConstants.wkbMultiPolygon,
        (MultiPolygon) geom, os);
  else if (geom instanceof GeometryCollection)
    writeGeometryCollection(WKBConstants.wkbGeometryCollection,
        (GeometryCollection) geom, os);
  else {
    Assert.shouldNeverReachHere("Unknown Geometry type");
  }
}
 
源代码3 项目: geomajas-project-server   文件: GeoServiceImpl.java
@Override
public Geometry createCircle(final Point point, final double radius, final int nrPoints) {
	double x = point.getX();
	double y = point.getY();
	Coordinate[] coords = new Coordinate[nrPoints + 1];
	for (int i = 0; i < nrPoints; i++) {
		double angle = ((double) i / (double) nrPoints) * Math.PI * 2.0;
		double dx = Math.cos(angle) * radius;
		double dy = Math.sin(angle) * radius;
		coords[i] = new Coordinate(x + dx, y + dy);
	}
	coords[nrPoints] = coords[0];

	LinearRing ring = point.getFactory().createLinearRing(coords);
	return point.getFactory().createPolygon(ring, null);
}
 
/**
 * Convert a layer type to a geometry class.
 * 
 * @param layerType
 *            layer type
 * @return JTS class
 */
public Class<? extends com.vividsolutions.jts.geom.Geometry> toInternal(LayerType layerType) {
	switch (layerType) {
		case GEOMETRY:
			return com.vividsolutions.jts.geom.Geometry.class;
		case LINESTRING:
			return LineString.class;
		case MULTILINESTRING:
			return MultiLineString.class;
		case POINT:
			return Point.class;
		case MULTIPOINT:
			return MultiPoint.class;
		case POLYGON:
			return Polygon.class;
		case MULTIPOLYGON:
			return MultiPolygon.class;
		case RASTER:
			return null;
		default:
			throw new IllegalStateException("Don't know how to handle layer type " + layerType);
	}
}
 
源代码5 项目: jts   文件: Distance3DOp.java
private void computeMinDistanceOneMulti(PlanarPolygon3D poly, Geometry geom, boolean flip) {
	if (geom instanceof GeometryCollection) {
		int n = geom.getNumGeometries();
		for (int i = 0; i < n; i++) {
			Geometry g = geom.getGeometryN(i);
			computeMinDistanceOneMulti(poly, g, flip);
			if (isDone)	return;
		}
	}
	else {
		if (geom instanceof Point) {
			computeMinDistancePolygonPoint(poly, (Point) geom, flip);
			return;
		}
		if (geom instanceof LineString) {
			computeMinDistancePolygonLine(poly, (LineString) geom, flip);
			return;
		}
		if (geom instanceof Polygon) {
			computeMinDistancePolygonPolygon(poly, (Polygon) geom, flip);
			return;
		}
	}
}
 
源代码6 项目: gama   文件: GamaKmlExport.java
/**
 * Add a placemark with a geometry object.The geometry can be a Point, a Line, a Polygon or any Multi-geometry.
 * Points will be represented by an icon and linear or surface objects will be drawn.
 *
 * @param label
 *            The title of the folder that will be created for this ShpRecord
 * @param beginDate
 *            Begining date of the timespan
 * @param endDate
 *            End date of the timespan
 * @param geom
 *            Geometry object to be drawn
 * @param height
 *            Height of the feature to draw. If > 0 the feature will be shown extruded to the given height
 *            (relative to the ground level). If <= 0 the feature will be drawn flat on the ground.
 */
public void addGeometry(final IScope scope, final String label, final String beginDate, final String endDate,
		final IShape shape, final String styleName, final double height) {
	final Placemark placemark = fold.createAndAddPlacemark().withStyleUrl("#" + styleName);
	placemark.setName(label);
	placemark.createAndSetTimeSpan().withBegin(beginDate).withEnd(endDate);

	final IShape shapeTM = Spatial.Projections.transform_CRS(scope, shape, "EPSG:4326");
	final Geometry geom = shapeTM.getInnerGeometry();

	if (geom instanceof Point) {
		addPoint(placemark, (Point) geom, height);
	} else if (geom instanceof LineString) {
		addLine(placemark, (LineString) geom, height);
	} else if (geom instanceof Polygon) {
		addPolygon(placemark, (Polygon) geom, height);
	} else if (geom instanceof MultiPoint) {
		addMultiPoint(placemark, (MultiPoint) geom, height);
	} else if (geom instanceof MultiLineString) {
		addMultiLine(placemark, (MultiLineString) geom, height);
	} else if (geom instanceof MultiPolygon) {
		addMultiPolygon(placemark, (MultiPolygon) geom, height);
	}
}
 
源代码7 项目: jts   文件: MiscellaneousTest.java
public void testPredicatesReturnFalseForEmptyGeometries() {
  Point p1 = new GeometryFactory().createPoint((Coordinate)null);
  Point p2 = new GeometryFactory().createPoint(new Coordinate(5,5));
  assertEquals(false, p1.equals(p2));
  assertEquals(true, p1.disjoint(p2));
  assertEquals(false, p1.intersects(p2));
  assertEquals(false, p1.touches(p2));
  assertEquals(false, p1.crosses(p2));
  assertEquals(false, p1.within(p2));
  assertEquals(false, p1.contains(p2));
  assertEquals(false, p1.overlaps(p2));

  assertEquals(false, p2.equals(p1));
  assertEquals(true, p2.disjoint(p1));
  assertEquals(false, p2.intersects(p1));
  assertEquals(false, p2.touches(p1));
  assertEquals(false, p2.crosses(p1));
  assertEquals(false, p2.within(p1));
  assertEquals(false, p2.contains(p1));
  assertEquals(false, p2.overlaps(p1));
}
 
源代码8 项目: TripleGeo   文件: ShpConnector.java
/**
  * 
  * Point geometry according to WGS84 Geoposition RDF vocabulary
  */
 private void insertWGS84Point(String resource, Geometry geo) 
 {
Point p = (Point) geo;
   insertLiteralTriplet(
       configuration.nsUri + resource,
       Constants.NSPOS + Constants.LONGITUDE,
       String.valueOf(p.getX()),     //X-ordinate as a property
       Constants.NSXSD + "decimal"
       );
   
   insertLiteralTriplet(
           configuration.nsUri + resource,
           Constants.NSPOS + Constants.LATITUDE,
           String.valueOf(p.getY()),   //Y-ordinate as a property
           Constants.NSXSD + "decimal"
           );

 }
 
源代码9 项目: rya   文件: GeoIndexerSfTest.java
/**
 * Rough conversion from geometry to GML using a template.
 * @param geo base Geometry gets delegated
 * @return String gml encoding of the gemoetry
 */
private static String geoToGmlRough(final Geometry geo) {
    final Geometries theType = org.geotools.geometry.jts.Geometries.get(geo);
    switch (theType) {
    case POINT:
        return geoToGml((Point)geo);
    case LINESTRING:
        return geoToGml((LineString)geo);
    case POLYGON:
        return geoToGml((Polygon)geo);
    case MULTIPOINT:
    case MULTILINESTRING:
    case MULTIPOLYGON:
    default:
        throw new Error("No code to convert to GML for this type: "+theType);
    }
}
 
/**
 * Convert a geometry class to a layer type.
 * 
 * @param geometryClass
 *            JTS geometry class
 * @return Geomajas layer type
 */
public LayerType toDto(Class<? extends com.vividsolutions.jts.geom.Geometry> geometryClass) {
	if (geometryClass == LineString.class) {
		return LayerType.LINESTRING;
	} else if (geometryClass == MultiLineString.class) {
		return LayerType.MULTILINESTRING;
	} else if (geometryClass == Point.class) {
		return LayerType.POINT;
	} else if (geometryClass == MultiPoint.class) {
		return LayerType.MULTIPOINT;
	} else if (geometryClass == Polygon.class) {
		return LayerType.POLYGON;
	} else if (geometryClass == MultiPolygon.class) {
		return LayerType.MULTIPOLYGON;
	} else {
		return LayerType.GEOMETRY;
	}
}
 
源代码11 项目: jts   文件: SameStructureTester.java
public static boolean isSameStructure(Geometry g1, Geometry g2)
{
  if (g1.getClass() != g2.getClass())
    return false;
  if (g1 instanceof GeometryCollection)
    return isSameStructureCollection((GeometryCollection) g1, (GeometryCollection) g2);
  else if (g1 instanceof Polygon)
    return isSameStructurePolygon((Polygon) g1, (Polygon) g2);
  else if (g1 instanceof LineString)
    return isSameStructureLineString((LineString) g1, (LineString) g2);
  else if (g1 instanceof Point)
    return isSameStructurePoint((Point) g1, (Point) g2);

  Assert.shouldNeverReachHere(
      "Unsupported Geometry class: " + g1.getClass().getName());
  return false;
}
 
源代码12 项目: jts   文件: FacetSequenceTreeBuilder.java
/**
 * Creates facet sequences
 * 
 * @param g
 * @return List<GeometryFacetSequence>
 */
private static List computeFacetSequences(Geometry g) {
  final List sections = new ArrayList();

  g.apply(new GeometryComponentFilter() {

    public void filter(Geometry geom) {
      CoordinateSequence seq = null;
      if (geom instanceof LineString) {
        seq = ((LineString) geom).getCoordinateSequence();
        addFacetSequences(seq, sections);
      }
      else if (geom instanceof Point) {
        seq = ((Point) geom).getCoordinateSequence();
        addFacetSequences(seq, sections);
      }
    }
  });
  return sections;
}
 
源代码13 项目: jts   文件: KMLWriter.java
private void writeGeometry(Geometry g, int level, StringBuffer buf) {
  String attributes = "";
  if (g instanceof Point) {
    writePoint((Point) g, attributes, level, buf);
  } else if (g instanceof LinearRing) {
    writeLinearRing((LinearRing) g, attributes, true, level, buf);
  } else if (g instanceof LineString) {
    writeLineString((LineString) g, attributes, level, buf);
  } else if (g instanceof Polygon) {
    writePolygon((Polygon) g, attributes, level, buf);
  } else if (g instanceof GeometryCollection) {
    writeGeometryCollection((GeometryCollection) g, attributes, level, buf);
  }
  else 
    throw new IllegalArgumentException("Geometry type not supported: " + g.getGeometryType());
}
 
private Class getGeometryBinding(LayerType layerType) {
	switch (layerType) {
		case LINESTRING:
			return Geometry.class;
		case MULTILINESTRING:
			return MultiLineString.class;
		case MULTIPOINT:
			return MultiPoint.class;
		case MULTIPOLYGON:
			return MultiPolygon.class;
		case POINT:
			return Point.class;
		case POLYGON:
			return Polygon.class;
		default:
			return Geometry.class;
	}
}
 
private void initDefaultWriters() {
	registerWriter(Bbox.class, new BboxWriter());
	registerWriter(Point.class, new PointWriter());
	registerWriter(LineString.class, new LineStringWriter());
	registerWriter(LinearRing.class, new LineStringWriter());
	registerWriter(Polygon.class, new PolygonWriter());
	registerWriter(MultiPoint.class, new MultiPointWriter());
	registerWriter(MultiLineString.class, new MultiLineStringWriter());
	registerWriter(MultiPolygon.class, new MultiPolygonWriter());
	registerWriter(GeometryCollection.class, new GeometryCollectionWriter());
}
 
@Test
public void setGeometry() throws Exception {
	WKTReader wktReader = new WKTReader();
	Point pt = (Point) wktReader.read("POINT (5 5)");
	featureModel.setGeometry(feature, pt);
	Assert.assertEquals(5, featureModel.getGeometry(feature).getCoordinate().x, 0.00001);
}
 
源代码17 项目: xyz-hub   文件: JTSHelper.java
/**
 * Create GeoJSON Point coordinates.
 */
public static PointCoordinates createPointCoordinates(Point geom) {
  if (geom == null) {
    return null;
  }
  final Coordinate coordinate = geom.getCoordinate();

  return (Double.isNaN(coordinate.z))
      ? new PointCoordinates(coordinate.x, coordinate.y) : new PointCoordinates(coordinate.x, coordinate.y, coordinate.z);
}
 
@Test
public void getGeometry() throws LayerException {
	Geometry geometry = featureModel.getGeometry(feature1);
	Assert.assertNotNull(geometry);
	Assert.assertTrue(geometry instanceof Point);
	Assert.assertEquals(3.0, geometry.getCoordinate().x, 0.00001);
	Assert.assertEquals(42.0, geometry.getCoordinate().y, 0.00001);

	geometry = featureModel.getGeometry(null);
	Assert.assertNull(geometry);
}
 
源代码19 项目: xyz-hub   文件: JTSHelper.java
@SuppressWarnings("unchecked")
public static <X extends com.here.xyz.models.geojson.implementation.Geometry> X fromGeometry(Geometry jtsGeometry) {
  if (jtsGeometry == null) {
    return null;
  }

  if (jtsGeometry instanceof Point) {
    return (X) new com.here.xyz.models.geojson.implementation.Point().withCoordinates(createPointCoordinates((Point) jtsGeometry));
  }
  if (jtsGeometry instanceof MultiPoint) {
    return (X) new com.here.xyz.models.geojson.implementation.MultiPoint()
        .withCoordinates(createMultiPointCoordinates((MultiPoint) jtsGeometry));
  }
  if (jtsGeometry instanceof LineString) {
    return (X) new com.here.xyz.models.geojson.implementation.LineString()
        .withCoordinates(createLineStringCoordinates((LineString) jtsGeometry));
  }
  if (jtsGeometry instanceof MultiLineString) {
    return (X) new com.here.xyz.models.geojson.implementation.MultiLineString()
        .withCoordinates(createMultiLineStringCoordinates((MultiLineString) jtsGeometry));
  }
  if (jtsGeometry instanceof Polygon) {
    return (X) new com.here.xyz.models.geojson.implementation.Polygon().withCoordinates(createPolygonCoordinates((Polygon) jtsGeometry));
  }
  if (jtsGeometry instanceof MultiPolygon) {
    return (X) new com.here.xyz.models.geojson.implementation.MultiPolygon()
        .withCoordinates(createMultiPolygonCoordinates((MultiPolygon) jtsGeometry));
  }
  if (jtsGeometry instanceof GeometryCollection) {
    return (X) fromGeometryCollection((GeometryCollection) jtsGeometry);
  }

  return null;
}
 
源代码20 项目: SensorWebClient   文件: DescribeSensorParserTest.java
@Test 
public void shouldParseLonLatOrdered4326PositionToCrs84Position() throws XmlException, IOException, FactoryException, TransformException {
    XmlObject sml = loadXmlFileViaClassloader(SML_POSITION_VECTOR_4326, getClass());
    DescribeSensorParser parser = createParserFromFile(sml, getForceXYOrderingMetadata());
    
    /*
     * We expect a lon/lat ordered coordinate as the inner CRS is CRS:84
     */
    Point actual = parser.buildUpSensorMetadataPosition();
    assertThat("X value (latitude) is incorrect.", actual.getX(), is(crs84Point.getX()));
    assertThat("Y value (longitude) is incorrect.", actual.getY(), is(crs84Point.getY()));
}
 
源代码21 项目: jts   文件: WKTReaderTest.java
public void testReadLargeNumbers() throws Exception {
  PrecisionModel precisionModel = new PrecisionModel(1E9);
  GeometryFactory geometryFactory = new GeometryFactory(precisionModel, 0);
  WKTReader reader = new WKTReader(geometryFactory);
  Geometry point1 = reader.read("POINT (123456789.01234567890 10)");
  Point point2 = geometryFactory.createPoint(new Coordinate(123456789.01234567890, 10));
  assertEquals(point1.getCoordinate().x, point2.getCoordinate().x, 1E-7);
  assertEquals(point1.getCoordinate().y, point2.getCoordinate().y, 1E-7);
}
 
@Override
public JSONObject jsonValueForSubject(Subject subject, Boolean timeStamp) {
    JSONObject obj = new JSONObject();
    Point centroid = subject.getShape().getCentroid();
    obj.put(label, centroid.getX());
    return obj;
}
 
@Override
public JSONObject jsonValueForSubject(Subject subject, Boolean timeStamp) {
    JSONObject obj = new JSONObject();
    Point centroid = subject.getShape().getCentroid();
    obj.put(label, centroid.getY());
    return obj;
}
 
源代码24 项目: geomajas-project-server   文件: GeoDbTest.java
@Test
public void testUpdate() throws GeomajasException, ParseException {
	// test updating geometry and name
	WKTReader wktReader = new WKTReader();
	Point geometry = (Point) wktReader.read("POINT (100 0)");
	SimpleFeatureBuilder build = new SimpleFeatureBuilder(pointLayer.getSchema());
	SimpleFeature feature = build.buildFeature("POINT.4", new Object[] { "point44", geometry });
	pointLayer.update(feature);
	SimpleFeature point4 = (SimpleFeature) pointLayer.read("POINT.4");
	Assert.assertEquals("point44", point4.getAttribute("NAME"));
	Assert.assertNotSame(geometry, point4.getDefaultGeometry());
	Assert.assertTrue(geometry.equalsTopo((Geometry) point4.getDefaultGeometry()));
}
 
源代码25 项目: sldeditor   文件: GeometryTypeMapping.java
/**
 * Populate member data
 */
private static void populate()
{
    geometryMap.put(Point.class, GeometryTypeEnum.POINT);
    geometryMap.put(MultiPoint.class, GeometryTypeEnum.POINT);
    geometryMap.put(LineString.class, GeometryTypeEnum.LINE);
    geometryMap.put(MultiLineString.class, GeometryTypeEnum.LINE);
    geometryMap.put(Polygon.class, GeometryTypeEnum.POLYGON);
    geometryMap.put(MultiPolygon.class, GeometryTypeEnum.POLYGON);
}
 
源代码26 项目: dhis2-core   文件: InternalMapObject.java
/**
 * Creates a feature type for a GeoTools geometric primitive.
 */
public SimpleFeatureType getFeatureType()
{
    String type;

    if ( geometry instanceof Point )
    {
        type = POINT;
    }
    else if ( geometry instanceof Polygon )
    {
        type = POLYGON;
    }
    else if ( geometry instanceof MultiPolygon )
    {
        type = MULTI_POLYGON;
    }
    else
    {
        throw new IllegalArgumentException();
    }

    try
    {
        return DataUtilities.createType( GEOMETRIES, "geometry:" + type + ":srid=3785" );
    }
    catch ( SchemaException ex )
    {
        throw new RuntimeException( "failed to create geometry", ex );
    }
}
 
源代码27 项目: dhis2-core   文件: GeoUtils.java
/**
 * Get GeometryJSON point.
 *
 * @param longitude the longitude.
 * @param latitude the latitude.
 * @return the GeoJSON representation of the given point.
 */
public static Point getGeoJsonPoint( double longitude, double latitude )
    throws IOException
{
    Point point;

    GeometryJSON gtjson = new GeometryJSON();

    point = gtjson.readPoint( new StringReader( "{\"type\":\"Point\", \"coordinates\":[" + longitude + ","
        + latitude + "]}" ) );

    point.setSRID( SRID );

    return point;
}
 
源代码28 项目: dhis2-core   文件: GeoUtils.java
/**
 * Check if the point coordinate falls within the polygon/MultiPolygon Shape
 *
 * @param longitude the longitude.
 * @param latitude the latitude.
 * @param geometry the GeoJSON coordinates of the MultiPolygon
 */
public static boolean checkPointWithMultiPolygon( double longitude, double latitude,
    Geometry geometry )
{
    try
    {
        boolean contains = false;

        Point point = getGeoJsonPoint( longitude, latitude );

        FeatureType featureType = FeatureType.getTypeFromName(geometry.getGeometryType());

        if ( point != null && point.isValid() )
        {
            if ( featureType == FeatureType.POLYGON )
            {
                Polygon polygon = (Polygon) geometry;
                contains = polygon.contains( point );
            }
            else if ( featureType == FeatureType.MULTI_POLYGON )
            {
                MultiPolygon multiPolygon = (MultiPolygon) geometry;
                contains = multiPolygon.contains( point );
            }
        }

        return contains;
    }
    catch ( Exception ex )
    {
        return false;
    }
}
 
源代码29 项目: sql-layer   文件: Spatial.java
public static SpatialObject deserializeWKT(Space space, String string) throws ParseException
{
    Geometry geometry = io.get().wktReader().read(string);
    return
        geometry instanceof Point
        ? JTS.spatialObject(space, (Point) geometry)
        : JTS.spatialObject(space, geometry);
}
 
源代码30 项目: jts   文件: OraReaderCreateTest.java
public void testRawGeometryCollectionWithPoint() throws Exception {
  final GeometryFactory geometryFactory = new GeometryFactory();
  final OraReader oraReader = new OraReader(geometryFactory);

  // Geometry type is a 'collection'.
  final int gType = 2004;
  // A collection of a 'line' and a 'point'/
  // The 'line' is starting at ordinate offset 1.
  // The 'point' is starting at ordinate offset 5.
  final int[] elemInfo = new int[] {1, 2, 1, 5, 1, 1};
  // 6 ordinates.
  // 'line' (1, 1, 2, 2).
  // 'point' (3, 3).
  final double[] ordinates = new double[] {1, 1, 2, 2, 3, 3};
  // Made 'create' method package private to enable test.
  final Geometry actual = oraReader.read(new OraGeom(gType, 0, elemInfo, ordinates));

  // Preparing expected result.
  final LineString lineString =
      geometryFactory.createLineString(new Coordinate[] {new Coordinate(1, 1), new Coordinate(2, 2)});
  final Point point = geometryFactory.createPoint(new Coordinate(3, 3));

  final List<Geometry> geometries = new ArrayList<Geometry>();
  geometries.add(lineString);
  geometries.add(point);

  final GeometryCollection expected =
      geometryFactory.createGeometryCollection(GeometryFactory.toGeometryArray(geometries));

  assertEquals(expected, actual);
}