com.vividsolutions.jts.geom.GeometryFactory Java Examples

The following examples show how to use com.vividsolutions.jts.geom.GeometryFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DiskLayout.java    From Getaviz with Apache License 2.0 7 votes vote down vote up
private void calculateRadiusForOuterCircles(Disk disk) {
	List<Disk> innerDisks = disk.getInnerDisks();
	CoordinateList coordinates = new CoordinateList();
	for (Disk d : innerDisks) {
		coordinates.add(d.getCoordinates(), false);
	}
	
	GeometryFactory geoFactory = new GeometryFactory();
	MultiPoint innerCirclemultipoint = geoFactory.createMultiPoint(coordinates.toCoordinateArray());
	MinimumBoundingCircle mbc = new MinimumBoundingCircle(innerCirclemultipoint);

	final double radius = mbc.getRadius();

	disk.updatePosition(mbc.getCentre().x,mbc.getCentre().y);
	disk.setRadius(disk.getBorderWidth() + radius + calculateB(calculateD(disk.getMinArea(), radius), radius));
	disk.setInnerRadius(radius);
	normalizePositionOfInnerCircles(disk);
}
 
Example #2
Source File: MergePolygonCommandTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testMergePolygon() throws Exception {
	MergePolygonRequest request = new MergePolygonRequest();
	GeometryFactory factory = new GeometryFactory();
	request.setPolygons(new Geometry[] {
			dtoConverter.toDto(geoService.createCircle(factory.createPoint(new Coordinate(0, 0)), 10, 10)),
			dtoConverter.toDto(geoService.createCircle(factory.createPoint(new Coordinate(5, 5)), 10, 10))});
	MergePolygonResponse response = (MergePolygonResponse) dispatcher.execute(
			MergePolygonRequest.COMMAND, request, null, "en");
	if (response.isError()) {
		response.getErrors().get(0).printStackTrace();
	}
	Assert.assertFalse(response.isError());
	Assert.assertNotNull(response.getGeometry());
	// @todo should verify that merge is correct
}
 
Example #3
Source File: MiscellaneousTest.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
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));
}
 
Example #4
Source File: SearchByLocationCommandTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void intersect50percentOverlapAlmost() throws Exception {
	// prepare command
	SearchByLocationRequest request = new SearchByLocationRequest();
	request.setCrs("EPSG:4326");
	request.setQueryType(SearchByLocationRequest.QUERY_INTERSECTS);
	request.setSearchType(SearchByLocationRequest.SEARCH_ALL_LAYERS);
	request.setRatio(0.5f);
	request.setLayerIds(new String[] {LAYER_ID});

	// create a rectangle that overlaps 49 %
	GeometryFactory factory = new GeometryFactory();
	LinearRing half1 = factory.createLinearRing(new Coordinate[] {new Coordinate(0, 0), new Coordinate(1, 0),
			new Coordinate(1, 0.49), new Coordinate(0, 0.49), new Coordinate(0, 0)});
	Polygon polygon = factory.createPolygon(half1, null);
	request.setLocation(converter.toDto(polygon));

	// execute
	SearchByLocationResponse response = (SearchByLocationResponse) dispatcher.execute(
			SearchByLocationRequest.COMMAND, request, null, "en");
	// test
	List<Feature> features = response.getFeatureMap().get(LAYER_ID);
	Assert.assertNull(features);
}
 
Example #5
Source File: GeometryInputDialog.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
Geometry parseGeometry(JTextComponent txt, Color clr) {
    try {
        WKTReader rdr =
            new WKTReader(
                new GeometryFactory(JTSTestBuilder.model().getPrecisionModel(), 0));
        Geometry g = rdr.read(txt.getText());
        txtError.setText("");
        return g;
    } catch (Exception ex) {
        txtError.setText(ex.getMessage());
        txtError.setForeground(clr);
        parseError = true;
        // TODO: display this exception
    }
    return null;
}
 
Example #6
Source File: GeoJsonReader.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Geometry createMultiPoint(Map<String, Object> geometryMap,
    GeometryFactory geometryFactory) throws ParseException {

  Geometry result = null;

  try {

    @SuppressWarnings("unchecked")
    List<List<Number>> coordinatesList = (List<List<Number>>) geometryMap
        .get(GeoJsonConstants.NAME_COORDINATES);

    CoordinateSequence coordinates = this
        .createCoordinateSequence(coordinatesList);

    result = geometryFactory.createMultiPoint(coordinates);

  } catch (RuntimeException e) {
    throw new ParseException(
        "Could not parse MultiPoint from GeoJson string.", e);
  }

  return result;
}
 
Example #7
Source File: PathEditor.java    From coordination_oru with GNU General Public License v3.0 6 votes vote down vote up
private Geometry makeObstacle(Pose p) {
	GeometryFactory gf = new GeometryFactory();
	Geometry geom = null;
	if (obstacleFootprint == null) {
		geom = gf.createPolygon(new Coordinate[] { new Coordinate(0.0,0.0), new Coordinate(0.0,OBSTACLE_SIZE), new Coordinate(OBSTACLE_SIZE,OBSTACLE_SIZE), new Coordinate(OBSTACLE_SIZE,0.0), new Coordinate(0.0,0.0) });
	}
	else {
		geom = gf.createPolygon(obstacleFootprint);
	}		
	AffineTransformation at = new AffineTransformation();
	at.rotate(p.getTheta());
	at.translate(p.getX(), p.getY());
	Geometry transGeom = at.transform(geom);
	Pose center = new Pose(p.getX(), p.getY(), p.getTheta());
	obstacles.add(transGeom);
	obstacleCenters.add(center);
	return transGeom;
}
 
Example #8
Source File: InvalidHoleRemover.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
public Polygon getResult()
{
  GeometryFactory gf = poly.getFactory();
  Polygon shell = gf.createPolygon((LinearRing) poly.getExteriorRing());
  PreparedGeometry shellPrep = PreparedGeometryFactory.prepare(shell);
  
  List holes = new ArrayList();
  for (int i = 0; i < poly.getNumInteriorRing(); i++) {
    LinearRing hole = (LinearRing) poly.getInteriorRingN(i);
    if (shellPrep.covers(hole)) {
      holes.add(hole);
    }
  }
  // all holes valid, so return original
  if (holes.size() == poly.getNumInteriorRing())
    return poly;
  
  // return new polygon with covered holes only
  Polygon result = gf.createPolygon((LinearRing) poly.getExteriorRing(), 
      GeometryFactory.toLinearRingArray(holes));
  return result;
}
 
Example #9
Source File: GeometryConverterTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
public GeometryConverterTest() {
	factory = new GeometryFactory(new PrecisionModel(), SRID);
	jtsC1 = new com.vividsolutions.jts.geom.Coordinate(10.0, 10.0);
	jtsC2 = new com.vividsolutions.jts.geom.Coordinate(20.0, 10.0);
	jtsC3 = new com.vividsolutions.jts.geom.Coordinate(20.0, 20.0);
	jtsC4 = new com.vividsolutions.jts.geom.Coordinate(10.0, 20.0);
	jtsC5 = new com.vividsolutions.jts.geom.Coordinate(12.0, 12.0);
	jtsC6 = new com.vividsolutions.jts.geom.Coordinate(12.0, 18.0);
	jtsC7 = new com.vividsolutions.jts.geom.Coordinate(18.0, 18.0);
	jtsC8 = new com.vividsolutions.jts.geom.Coordinate(18.0, 12.0);

	dtoC1 = new Coordinate(10.0, 10.0);
	dtoC2 = new Coordinate(20.0, 10.0);
	dtoC3 = new Coordinate(20.0, 20.0);
	dtoC4 = new Coordinate(10.0, 20.0);
	dtoC5 = new Coordinate(12.0, 12.0);
	dtoC6 = new Coordinate(12.0, 18.0);
	dtoC7 = new Coordinate(18.0, 18.0);
	dtoC8 = new Coordinate(18.0, 12.0);
}
 
Example #10
Source File: CreateRandomShapeFunctions.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static Geometry randomRadialPoints(Geometry g, int nPts) {
  Envelope env = FunctionsUtil.getEnvelopeOrDefault(g);
  GeometryFactory geomFact = FunctionsUtil.getFactoryOrDefault(g);
  double xLen = env.getWidth();
  double yLen = env.getHeight();
  double rMax = Math.min(xLen, yLen) / 2.0;
  
  double centreX = env.getMinX() + xLen/2;
  double centreY = env.getMinY() + yLen/2;
  
  List pts = new ArrayList();

  for (int i = 0; i < nPts; i++) {
    double rand = Math.random();
    // use rand^2 to accentuate radial distribution
    double r = rMax * rand * rand;
    // produces even distribution
    //double r = rMax * Math.sqrt(rand);
    double ang = 2 * Math.PI * Math.random();
    double x = centreX + r * Math.cos(ang);
    double y = centreY + r * Math.sin(ang);
    pts.add(geomFact.createPoint(new Coordinate(x, y)));
  }
  return geomFact.buildGeometry(pts);
}
 
Example #11
Source File: CreateRandomShapeFunctions.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static Geometry randomSegments(Geometry g, int nPts) {
  Envelope env = FunctionsUtil.getEnvelopeOrDefault(g);
  GeometryFactory geomFact = FunctionsUtil.getFactoryOrDefault(g);
  double xLen = env.getWidth();
  double yLen = env.getHeight();

  List lines = new ArrayList();

  for (int i = 0; i < nPts; i++) {
    double x0 = env.getMinX() + xLen * Math.random();
    double y0 = env.getMinY() + yLen * Math.random();
    double x1 = env.getMinX() + xLen * Math.random();
    double y1 = env.getMinY() + yLen * Math.random();
    lines.add(geomFact.createLineString(new Coordinate[] {
        new Coordinate(x0, y0), new Coordinate(x1, y1) }));
  }
  return geomFact.buildGeometry(lines);
}
 
Example #12
Source File: CreateRandomShapeFunctions.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static Geometry randomSegmentsInGrid(Geometry g, int nPts) {
  Envelope env = FunctionsUtil.getEnvelopeOrDefault(g);
  GeometryFactory geomFact = FunctionsUtil.getFactoryOrDefault(g);

  int nCell = (int) Math.sqrt(nPts) + 1;

  double xLen = env.getWidth() / nCell;
  double yLen = env.getHeight() / nCell;

  List lines = new ArrayList();

  for (int i = 0; i < nCell; i++) {
    for (int j = 0; j < nCell; j++) {
      double x0 = env.getMinX() + i * xLen + xLen * Math.random();
      double y0 = env.getMinY() + j * yLen + yLen * Math.random();
      double x1 = env.getMinX() + i * xLen + xLen * Math.random();
      double y1 = env.getMinY() + j * yLen + yLen * Math.random();
      lines.add(geomFact.createLineString(new Coordinate[] {
          new Coordinate(x0, y0), new Coordinate(x1, y1) }));
    }
  }
  return geomFact.buildGeometry(lines);
}
 
Example #13
Source File: PersistTransactionCommandTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
@DirtiesContext // adding a bean
public void testPersistAddFeatureTransaction() throws Exception {
	PersistTransactionRequest request = new PersistTransactionRequest();
	request.setCrs(CRS);
	FeatureTransaction featureTransaction = new FeatureTransaction();
	featureTransaction.setLayerId(LAYER_ID);
	Feature feature = new Feature();
	GeometryFactory factory = new GeometryFactory();
	Geometry circle =
			dtoConverter.toDto(geoService.createCircle(factory.createPoint(new Coordinate(0, 0)), 10, 10));
	feature.setGeometry(circle);
	featureTransaction.setNewFeatures(new Feature[] {feature});
	request.setFeatureTransaction(featureTransaction);
	PersistTransactionResponse response = (PersistTransactionResponse) dispatcher.execute(
			PersistTransactionRequest.COMMAND, request, null, "en");
	if (response.isError()) {
		response.getErrors().get(0).printStackTrace();
	}
	Assert.assertFalse(response.isError());
	Assert.assertNotNull(response.getFeatureTransaction());
	Feature[] newFeatures = response.getFeatureTransaction().getNewFeatures();
	Assert.assertEquals(1, newFeatures.length);
	Assert.assertNotNull(newFeatures[0].getId());
}
 
Example #14
Source File: AllowAllAuthorization.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
protected Geometry getAuthorizedArea(String layerId) {
	if (null == biggestGeometry) {
		// build Geometry which covers biggest possible area
		Envelope maxBounds = new Envelope(-Float.MAX_VALUE, Float.MAX_VALUE, -Float.MAX_VALUE, Float.MAX_VALUE);
		PrecisionModel precisionModel = new PrecisionModel(PrecisionModel.FLOATING);
		GeometryFactory geometryFactory = new GeometryFactory(precisionModel, 0);
		biggestGeometry = geometryFactory.toGeometry(maxBounds);
	}
	return biggestGeometry;
}
 
Example #15
Source File: GeometryCoordinateReplacer.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Gets the snapped coordinate array for an atomic geometry,
 * or null if it has collapsed.
 * 
 * @return the snapped coordinate array for this geometry
 * @return null if the snapped coordinates have collapsed, or are missing
 */
public CoordinateSequence edit(CoordinateSequence coordSeq, Geometry geometry, GeometryFactory targetFactory) {
  if (geometryLinesMap.containsKey(geometry)) {
    Coordinate[] pts = (Coordinate[]) geometryLinesMap.get(geometry);
    // Assert: pts should always have length > 0
    boolean isValidPts = isValidSize(pts, geometry);
    if (! isValidPts) return null;
    return targetFactory.getCoordinateSequenceFactory().create(pts);
  }
  //TODO: should this return null if no matching snapped line is found
  // probably should never reach here?
  return coordSeq;
}
 
Example #16
Source File: PolygonCleaner.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Geometry edit(Geometry geometry, GeometryFactory targetFactory) {
  if (geometry instanceof Polygonal) {
    return geometry.buffer(0);
  }
  return geometry;
}
 
Example #17
Source File: GeometryBoxDeleter.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Geometry edit(Geometry geometry, GeometryFactory factory)
{
  // Allow any number of components to be deleted
  //if (isEdited) return geometry;
  if (env.contains(geometry.getEnvelopeInternal())) {
      isEdited = true;
      return null;
  }
  return geometry;
}
 
Example #18
Source File: LayerList.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Geometry extractComponents(Geometry parentGeom, Geometry aoi)
{
  ComponentLocater locater = new ComponentLocater(parentGeom);
  List locs = locater.getComponents(aoi);
  List geoms = extractLocationGeometry(locs);
  if (geoms.size() <= 0)
    return null;
  if (geoms.size() == 1) 
    return (Geometry) geoms.get(0);
  // if parent was a GC, ensure returning a GC
  if (parentGeom.getGeometryType().equals("GeometryCollection"))
    return parentGeom.getFactory().createGeometryCollection(GeometryFactory.toGeometryArray(geoms));
  // otherwise return MultiGeom
  return parentGeom.getFactory().buildGeometry(geoms);
}
 
Example #19
Source File: ShapeFile.java    From tutorials with MIT License 5 votes vote down vote up
static void addLocations(SimpleFeatureType CITY, DefaultFeatureCollection collection) {

        Map<String, List<Double>> locations = new HashMap<>();

        double lat = 13.752222;
        double lng = 100.493889;
        addToLocationMap("Bangkok", lat, lng, locations);

        lat = 53.083333;
        lng = -0.15;
        addToLocationMap("New York", lat, lng, locations);

        lat = -33.925278;
        lng = 18.423889;
        addToLocationMap("Cape Town", lat, lng, locations);

        lat = -33.859972;
        lng = 151.211111;
        addToLocationMap("Sydney", lat, lng, locations);

        lat = 45.420833;
        lng = -75.69;
        addToLocationMap("Ottawa", lat, lng, locations);

        lat = 30.07708;
        lng = 31.285909;
        addToLocationMap("Cairo", lat, lng, locations);

        GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);

        locations.entrySet().stream()
          .map(toFeature(CITY, geometryFactory))
          .forEach(collection::add);
    }
 
Example #20
Source File: ShapeFile.java    From tutorials with MIT License 5 votes vote down vote up
private static Function<Map.Entry<String, List<Double>>, SimpleFeature> toFeature(SimpleFeatureType CITY, GeometryFactory geometryFactory) {
    return location -> {
        Point point = geometryFactory.createPoint(
          new Coordinate(location.getValue()
            .get(0), location.getValue().get(1)));

        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(CITY);
        featureBuilder.add(point);
        featureBuilder.add(location.getKey());
        return featureBuilder.buildFeature(null);
    };
}
 
Example #21
Source File: StyleConverterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
private Geometry toGeometry(GeometryFactory factory, AbstractGeometryInfo geom) throws LayerException {
	Geometry geometry = null;
	if (geom instanceof AbstractGeometryCollectionInfo) {
		AbstractGeometryCollectionInfo geomCollection = (AbstractGeometryCollectionInfo) geom;
		List<GeometryMemberInfo> members = geomCollection.getGeometryMemberList();
		if (geom instanceof MultiPointInfo) {
			Point[] points = new Point[members.size()];
			for (int i = 0; i < members.size(); i++) {
				points[i] = (Point) toSimpleGeometry(factory, members.get(i).getGeometry());
			}
			geometry = factory.createMultiPoint(points);
		} else if (geom instanceof MultiLineStringInfo) {
			LineString[] lines = new LineString[members.size()];
			for (int i = 0; i < members.size(); i++) {
				lines[i] = (LineString) toSimpleGeometry(factory, members.get(i).getGeometry());
			}
			geometry = factory.createMultiLineString(lines);
		} else if (geom instanceof MultiPolygonInfo) {
			Polygon[] polygons = new Polygon[members.size()];
			for (int i = 0; i < members.size(); i++) {
				polygons[i] = (Polygon) toSimpleGeometry(factory, members.get(i).getGeometry());
			}
			geometry = factory.createMultiPolygon(polygons);
		} else if (geom instanceof MultiGeometryInfo) {
			Geometry[] geometries = new Geometry[members.size()];
			for (int i = 0; i < members.size(); i++) {
				geometries[i] = toGeometry(factory, members.get(i).getGeometry());
			}
			geometry = factory.createGeometryCollection(geometries);
		}
	} else {
		geometry = toSimpleGeometry(factory, geom);
	}
	return geometry;
}
 
Example #22
Source File: GeoServiceTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testCalcDefaultLabelPosition() throws Exception {
	Geometry geometry;
	GeometryFactory factory = new GeometryFactory(new PrecisionModel(), 4326);
	Coordinate coordinate;
	InternalFeature feature = new InternalFeatureImpl();
	feature.setId("x");
	feature.setLabel("Label x");
	coordinate = geoService.calcDefaultLabelPosition(feature);
	Assert.assertNull(coordinate);

	feature.setGeometry(factory.createMultiPolygon(new Polygon[] {}));
	coordinate = geoService.calcDefaultLabelPosition(feature);
	Assert.assertNull(coordinate);

	feature.setGeometry(JTS.toGeometry(new Envelope(10, 20, 30, 40)));
	coordinate = geoService.calcDefaultLabelPosition(feature);
	// this tests current behaviour, without claims that this is the "best" (or even "good") position
	Assert.assertEquals(15.0, coordinate.x, DELTA);
	Assert.assertEquals(35.0, coordinate.y, DELTA);

	geometry = factory.createLineString(new Coordinate[] { new Coordinate(5,4), new Coordinate(30,10) });
	feature.setGeometry(geometry);
	coordinate = geoService.calcDefaultLabelPosition(feature);
	// this tests current behaviour, without claims that this is the "best" (or even "good") position
	Assert.assertEquals(5.0, coordinate.x, DELTA);
	Assert.assertEquals(4.0, coordinate.y, DELTA);
}
 
Example #23
Source File: SOSSelectionChangedHandler.java    From SensorWebClient with GNU General Public License v2.0 5 votes vote down vote up
private BoundingBox createBoundingBox(Record record) {
    Double llEasting = Double.parseDouble(getValueFor(record, "llEasting"));
    Double llNorthing = Double.parseDouble(getValueFor(record, "llNorthing"));
    Double urEasting = Double.parseDouble(getValueFor(record, "urEasting"));
    Double urNorthing = Double.parseDouble(getValueFor(record, "urNorthing"));

    GeometryFactory factory = new GeometryFactory(new PrecisionModel(), 4326);
    Point ll = factory.createPoint(new Coordinate(llEasting, llNorthing));
    Point ur = factory.createPoint(new Coordinate(urEasting, urNorthing));
    return new BoundingBox(ll, ur, "EPSG:4326");
}
 
Example #24
Source File: CreateRandomShapeFunctions.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Geometry randomLineString(Geometry g, int nPts) {
  Envelope env = FunctionsUtil.getEnvelopeOrDefault(g);
  GeometryFactory geomFact = FunctionsUtil.getFactoryOrDefault(g);
  double width = env.getWidth();
  double hgt = env.getHeight();

  Coordinate[] pts = new Coordinate[nPts];

  for (int i = 0; i < nPts; i++) {
    double xLen = width * Math.random();
    double yLen = hgt * Math.random();
    pts[i] = randomPtInRectangleAround(env.centre(), xLen, yLen);
  }
  return geomFact.createLineString(pts);
}
 
Example #25
Source File: DividePolygonTool.java    From geowe-core with GNU General Public License v3.0 5 votes vote down vote up
private Geometry getGeometry(final String wkt) {
	Geometry geom = null;
	final GeometryFactory factory = new GeometryFactory(
			PackedCoordinateSequenceFactory.DOUBLE_FACTORY);
	final WKTReader reader = new WKTReader(factory);
	try {
		geom = reader.read(wkt);
	} catch (ParseException e) {			
		LOG.error(INVALID_WKT_MESSAGE + e.getMessage());
		throw new IllegalArgumentException(INVALID_WKT_MESSAGE, e);
	}

	return geom;
}
 
Example #26
Source File: CreateRandomShapeFunctions.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Geometry randomPointsInTriangle(Geometry g, int nPts) {
  GeometryFactory geomFact = FunctionsUtil.getFactoryOrDefault(g);
  Coordinate[] gpts = g.getCoordinates();
  Coordinate tri0 = gpts[0];
  Coordinate tri1 = gpts[1];
  Coordinate tri2 = gpts[2];
  
  List pts = new ArrayList();

  for (int i = 0; i < nPts; i++) {
    pts.add(geomFact.createPoint(randomPointInTriangle(tri0, tri1, tri2)));
  }
  return geomFact.buildGeometry(pts);
}
 
Example #27
Source File: WKTWriterTest.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testWrite3D_withNaN() {
  GeometryFactory geometryFactory = new GeometryFactory();
  Coordinate[] coordinates = { new Coordinate(1, 1),
                               new Coordinate(2, 2, 2) };
  LineString line = geometryFactory.createLineString(coordinates);
  String wkt = writer3D.write(line);
  assertEquals("LINESTRING (1 1, 2 2 2)", wkt);
}
 
Example #28
Source File: QuadEdgeTriangle.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Geometry toPolygon(Vertex[] v) {
	Coordinate[] ringPts = new Coordinate[] { v[0].getCoordinate(),
			v[1].getCoordinate(), v[2].getCoordinate(), v[0].getCoordinate() };
	GeometryFactory fact = new GeometryFactory();
	LinearRing ring = fact.createLinearRing(ringPts);
	Polygon tri = fact.createPolygon(ring, null);
	return tri;
}
 
Example #29
Source File: OddFeatureAuthorization.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
protected Geometry getAuthorizedArea(String layerId) {
	if (null == biggestGeometry) {
		// build Geometry which covers biggest possible area
		Envelope maxBounds = new Envelope(-Double.MAX_VALUE, Double.MAX_VALUE,
				-Double.MAX_VALUE, Double.MAX_VALUE);
		PrecisionModel precisionModel = new PrecisionModel(PrecisionModel.FLOATING);
		GeometryFactory geometryFactory = new GeometryFactory(precisionModel, 0);
		biggestGeometry = geometryFactory.toGeometry(maxBounds);
	}
	return biggestGeometry;
}
 
Example #30
Source File: IOUtil.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Geometry readWKBHexString(String wkb, GeometryFactory geomFact)
throws ParseException, IOException 
{
  WKBReader reader = new WKBReader(geomFact);
  WKBHexFileReader fileReader = new WKBHexFileReader(new StringReader(wkb), reader);
  List geomList = fileReader.read();
  
  if (geomList.size() == 1)
    return (Geometry) geomList.get(0);
  
  return geomFact.createGeometryCollection(GeometryFactory.toGeometryArray(geomList));
}