com.vividsolutions.jts.geom.MultiLineString Java Examples

The following examples show how to use com.vividsolutions.jts.geom.MultiLineString. 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: WKTWriter.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 *  Converts a <code>MultiLineString</code> to &lt;MultiLineString Text&gt;
 *  format, then appends it to the writer.
 *
 *@param  multiLineString  the <code>MultiLineString</code> to process
 *@param  writer           the output writer to append to
 */
private void appendMultiLineStringText(MultiLineString multiLineString, int level, boolean indentFirst,
    Writer writer)
  throws IOException
{
  if (multiLineString.isEmpty()) {
    writer.write("EMPTY");
  }
  else {
    int level2 = level;
    boolean doIndent = indentFirst;
    writer.write("(");
    for (int i = 0; i < multiLineString.getNumGeometries(); i++) {
      if (i > 0) {
        writer.write(", ");
        level2 = level + 1;
        doIndent = true;
      }
      appendLineStringText((LineString) multiLineString.getGeometryN(i), level2, doIndent, writer);
    }
    writer.write(")");
  }
}
 
Example #2
Source File: WKBWriter.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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");
  }
}
 
Example #3
Source File: AllowedAttributeTypes.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #4
Source File: GeometryConverterTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
private com.vividsolutions.jts.geom.Geometry createJtsEmpty(Class<?> clazz) {
	if (Point.class.equals(clazz)) {
		return factory.createPoint((com.vividsolutions.jts.geom.Coordinate) null);
	} else if (LineString.class.equals(clazz)) {
		return factory.createLineString((com.vividsolutions.jts.geom.Coordinate[]) null);
	} else if (LinearRing.class.equals(clazz)) {
		return factory.createLinearRing((com.vividsolutions.jts.geom.Coordinate[]) null);
	} else if (Polygon.class.equals(clazz)) {
		return factory.createPolygon(null, null);
	} else if (MultiPoint.class.equals(clazz)) {
		return factory.createMultiPoint((Point[]) null);
	} else if (MultiLineString.class.equals(clazz)) {
		return factory.createMultiLineString((LineString[]) null);
	} else if (MultiPolygon.class.equals(clazz)) {
		return factory.createMultiPolygon((Polygon[]) null);
	} else {
		return null;
	}
}
 
Example #5
Source File: GeometryConverterTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void dtoEmptyToJts() throws GeomajasException {
	// Test DTO Point to JTS:
	LineString ls = (LineString) converter.toInternal(createDtoEmpty(Geometry.LINE_STRING));
	Assert.assertTrue(ls.isEmpty());
	LinearRing lr = (LinearRing) converter.toInternal(createDtoEmpty(Geometry.LINEAR_RING));
	Assert.assertTrue(lr.isEmpty());
	MultiLineString mls = (MultiLineString) converter.toInternal(createDtoEmpty(Geometry.MULTI_LINE_STRING));
	Assert.assertTrue(mls.isEmpty());
	MultiPoint mp = (MultiPoint) converter.toInternal(createDtoEmpty(Geometry.MULTI_POINT));
	Assert.assertTrue(mp.isEmpty());
	MultiPolygon mpo = (MultiPolygon) converter.toInternal(createDtoEmpty(Geometry.MULTI_POLYGON));
	Assert.assertTrue(mpo.isEmpty());
	Point p = (Point) converter.toInternal(createDtoEmpty(Geometry.POINT));
	Assert.assertTrue(p.isEmpty());
	Polygon po = (Polygon) converter.toInternal(createDtoEmpty(Geometry.POLYGON));
	Assert.assertTrue(po.isEmpty());
}
 
Example #6
Source File: GeometryConverterTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void jtsEmptyToDto() throws GeomajasException {
	Geometry p = converter.toDto(createJtsEmpty(Point.class));
	Assert.assertEquals(Geometry.POINT, p.getGeometryType());
	Assert.assertTrue(GeometryService.isEmpty(p));
	Geometry ls = converter.toDto(createJtsEmpty(LineString.class));
	Assert.assertEquals(Geometry.LINE_STRING, ls.getGeometryType());
	Assert.assertTrue(GeometryService.isEmpty(ls));
	Geometry lr = converter.toDto(createJtsEmpty(LinearRing.class));
	Assert.assertEquals(Geometry.LINEAR_RING, lr.getGeometryType());
	Assert.assertTrue(GeometryService.isEmpty(lr));
	Geometry po = converter.toDto(createJtsEmpty(Polygon.class));
	Assert.assertEquals(Geometry.POLYGON, po.getGeometryType());
	Assert.assertTrue(GeometryService.isEmpty(po));
	assertThat(po.getGeometries()).isNull();
	Geometry mp = converter.toDto(createJtsEmpty(MultiPoint.class));
	Assert.assertEquals(Geometry.MULTI_POINT, mp.getGeometryType());
	Assert.assertTrue(GeometryService.isEmpty(mp));
	Geometry mpo = converter.toDto(createJtsEmpty(MultiPolygon.class));
	Assert.assertEquals(Geometry.MULTI_POLYGON, mpo.getGeometryType());
	Assert.assertTrue(GeometryService.isEmpty(mpo));
	Geometry mls = converter.toDto(createJtsEmpty(MultiLineString.class));
	Assert.assertEquals(Geometry.MULTI_LINE_STRING, mls.getGeometryType());
	Assert.assertTrue(GeometryService.isEmpty(mls));
}
 
Example #7
Source File: LayerTypeConverterTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testConversion() {
	// dto -> internal
	for (LayerType layerType : LayerType.values()) {
		if (layerType != LayerType.RASTER) {
			Class<? extends Geometry> c = converterService.toInternal(layerType);
			Assert.assertEquals(layerType.name(), c.getSimpleName().toUpperCase());
		} else {
			Assert.assertNull(converterService.toInternal(layerType));
		}
	}
	// internal -> dto
	Assert.assertEquals(LayerType.POINT, converterService.toDto(Point.class));
	Assert.assertEquals(LayerType.MULTIPOINT, converterService.toDto(MultiPoint.class));
	Assert.assertEquals(LayerType.LINESTRING, converterService.toDto(LineString.class));
	Assert.assertEquals(LayerType.MULTILINESTRING, converterService.toDto(MultiLineString.class));
	Assert.assertEquals(LayerType.POLYGON, converterService.toDto(Polygon.class));
	Assert.assertEquals(LayerType.MULTIPOLYGON, converterService.toDto(MultiPolygon.class));
	Assert.assertEquals(LayerType.GEOMETRY, converterService.toDto(Geometry.class));
}
 
Example #8
Source File: GamaKmlExport.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example #9
Source File: OraGeom.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns the GTYPE GEOM_TYPE code
 * corresponding to the geometry type.
 * 
 * @see OraGeom.GEOM_TYPE
 *
 * @param geom the geometry to compute the GEOM_TYPE for
 * @return geom type code, if known, or UNKNOWN
 */
static int geomType(Geometry geom) {
  if (geom == null) {
      return OraGeom.GEOM_TYPE.UNKNOWN_GEOMETRY; 
  } else if (geom instanceof Point) {
      return OraGeom.GEOM_TYPE.POINT;
  } else if (geom instanceof LineString) {
      return OraGeom.GEOM_TYPE.LINE;
  } else if (geom instanceof Polygon) {
      return OraGeom.GEOM_TYPE.POLYGON;
  } else if (geom instanceof MultiPoint) {
      return OraGeom.GEOM_TYPE.MULTIPOINT;
  } else if (geom instanceof MultiLineString) {
      return OraGeom.GEOM_TYPE.MULTILINE;
  } else if (geom instanceof MultiPolygon) {
      return OraGeom.GEOM_TYPE.MULTIPOLYGON;
  } else if (geom instanceof GeometryCollection) {
      return OraGeom.GEOM_TYPE.COLLECTION;
  }
  return OraGeom.GEOM_TYPE.UNKNOWN_GEOMETRY; 
}
 
Example #10
Source File: SaveStatement.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
public static String getGeometryType(final List<? extends IShape> agents) {
	String geomType = "";
	for (final IShape be : agents) {
		final IShape geom = be.getGeometry();
		if (geom != null && geom.getInnerGeometry() != null) {
			geomType = geom.getInnerGeometry().getClass().getSimpleName();
			if (geom.getInnerGeometry().getNumGeometries() > 1) {
				if (geom.getInnerGeometry().getGeometryN(0).getClass() == Point.class) {
					geomType = MultiPoint.class.getSimpleName();
				} else if (geom.getInnerGeometry().getGeometryN(0).getClass() == LineString.class) {
					geomType = MultiLineString.class.getSimpleName();
				} else if (geom.getInnerGeometry().getGeometryN(0).getClass() == Polygon.class) {
					geomType = MultiPolygon.class.getSimpleName();
				}
				break;
			}
		}
	}
	if ("DynamicLineString".equals(geomType)) {
		geomType = LineString.class.getSimpleName();
	}
	return geomType;
}
 
Example #11
Source File: InternalFeatureCollection.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
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;
	}
}
 
Example #12
Source File: DtoConverterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 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;
	}
}
 
Example #13
Source File: DtoConverterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example #14
Source File: VectorLayerComponentImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
private void drawFeature(PdfContext context, ClientMapInfo map, InternalFeature f) {
	FeatureStyleInfo style = f.getStyleInfo();

	// Color, transparency, dash
	Color fillColor = context.getColor(style.getFillColor(), style.getFillOpacity());
	Color strokeColor = context.getColor(style.getStrokeColor(), style.getStrokeOpacity());
	float[] dashArray = context.getDashArray(style.getDashArray());

	// check if the feature is selected
	if (selectedFeatures.contains(f.getId())) {
		if (f.getGeometry() instanceof MultiPolygon || f.getGeometry() instanceof Polygon) {
			style = mergeStyle(style, map.getPolygonSelectStyle());
			fillColor = context.getColor(style.getFillColor(), style.getFillOpacity());
			strokeColor = context.getColor(style.getStrokeColor(), style.getStrokeOpacity());
		} else if (f.getGeometry() instanceof MultiLineString || f.getGeometry() instanceof LineString) {
			style = mergeStyle(style, map.getLineSelectStyle());
			strokeColor = context.getColor(style.getStrokeColor(), style.getStrokeOpacity());
		} else if (f.getGeometry() instanceof MultiPoint || f.getGeometry() instanceof Point) {
			style = mergeStyle(style, map.getPointSelectStyle());
			strokeColor = context.getColor(style.getStrokeColor(), style.getStrokeOpacity());
		}
	}

	float lineWidth = style.getStrokeWidth();

	SymbolInfo symbol = null;
	if (f.getGeometry() instanceof MultiPoint || f.getGeometry() instanceof Point) {
		symbol = style.getSymbol();
	}
	// clone geometry
	Geometry geometry = (Geometry) f.getGeometry().clone();
	// transform to user space
	geometry.apply(new MapToUserFilter());
	// notify geometry change !!!
	geometry.geometryChanged();
	// now draw
	context.drawGeometry(geometry, symbol, fillColor, strokeColor, lineWidth, dashArray, getSize());
}
 
Example #15
Source File: DefaultVmlDocument.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
private void initDefaultWriters() {
	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());
}
 
Example #16
Source File: ShapeInMemFeatureModel.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Geometry getGeometry(Object feature) throws LayerException {
	Geometry geom = (Geometry) asFeature(feature).getDefaultGeometry();
	if (geom instanceof MultiLineString && vectorLayerInfo.getLayerType() == LayerType.LINESTRING) {
		return (Geometry) geom.getGeometryN(0).clone();
	} else if (geom instanceof MultiPolygon && vectorLayerInfo.getLayerType() == LayerType.POLYGON) {
		return (Geometry) geom.getGeometryN(0).clone();
	} else if (geom instanceof MultiPoint && vectorLayerInfo.getLayerType() == LayerType.POINT) {
		return (Geometry) geom.getGeometryN(0).clone();
	}
	return (Geometry) geom.clone();
}
 
Example #17
Source File: MultiLineStringTest.java    From jackson-datatype-jts with Apache License 2.0 5 votes vote down vote up
@Override
protected MultiLineString createGeometry() {
    return gf
            .createMultiLineString(new LineString[] {
                    gf.createLineString(new Coordinate[] {
                            new Coordinate(100.0, 0.0),
                            new Coordinate(101.0, 1.0) }),
                    gf.createLineString(new Coordinate[] {
                            new Coordinate(102.0, 2.0),
                            new Coordinate(103.0, 3.0) }) });
}
 
Example #18
Source File: PdfContext.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
private void drawGeometry(Geometry g, SymbolInfo symbol) {
	if (g instanceof MultiPolygon) {
		MultiPolygon mpoly = (MultiPolygon) g;
		for (int i = 0; i < mpoly.getNumGeometries(); i++) {
			drawGeometry(mpoly.getGeometryN(i), symbol);
		}
	} else if (g instanceof MultiLineString) {
		MultiLineString mline = (MultiLineString) g;
		for (int i = 0; i < mline.getNumGeometries(); i++) {
			drawGeometry(mline.getGeometryN(i), symbol);
		}
	} else if (g instanceof MultiPoint) {
		MultiPoint mpoint = (MultiPoint) g;
		for (int i = 0; i < mpoint.getNumGeometries(); i++) {
			drawGeometry(mpoint.getGeometryN(i), symbol);
		}
	} else if (g instanceof Polygon) {
		Polygon poly = (Polygon) g;
		LineString shell = poly.getExteriorRing();
		int nHoles = poly.getNumInteriorRing();
		drawPathContent(shell.getCoordinates());
		for (int j = 0; j < nHoles; j++) {
			drawPathContent(poly.getInteriorRingN(j).getCoordinates());
		}
		template.closePathEoFillStroke();
	} else if (g instanceof LineString) {
		LineString line = (LineString) g;
		drawPathContent(line.getCoordinates());
		template.stroke();
	} else if (g instanceof Point) {
		Point point = (Point) g;
		drawPoint(point.getCoordinate(), symbol);
		template.fillStroke();
	}
}
 
Example #19
Source File: GeoToolsLayerBeanFactory.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
private void setLayerType(VectorLayerInfo info, GeometryDescriptor geoType) {
	if (geoType.getType().getBinding() == Point.class) {
		info.setLayerType(LayerType.POINT);
	} else if (geoType.getType().getBinding() == MultiPoint.class) {
		info.setLayerType(LayerType.MULTIPOINT);
	} else if (geoType.getType().getBinding() == LineString.class) {
		info.setLayerType(LayerType.LINESTRING);
	} else if (geoType.getType().getBinding() == MultiLineString.class) {
		info.setLayerType(LayerType.MULTILINESTRING);
	} else if (geoType.getType().getBinding() == Polygon.class) {
		info.setLayerType(LayerType.POLYGON);
	} else if (geoType.getType().getBinding() == MultiPolygon.class) {
		info.setLayerType(LayerType.MULTIPOLYGON);
	}
}
 
Example #20
Source File: JTSHelper.java    From xyz-hub with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a JTS Geometry from the provided GeoJSON geometry.
 */
@SuppressWarnings("unchecked")
public static <X extends Geometry> X toGeometry(com.here.xyz.models.geojson.implementation.Geometry geometry) {
  if (geometry == null) {
    return null;
  }

  if (geometry instanceof com.here.xyz.models.geojson.implementation.Point) {
    return (X) toPoint(((com.here.xyz.models.geojson.implementation.Point) geometry).getCoordinates());
  }
  if (geometry instanceof com.here.xyz.models.geojson.implementation.MultiPoint) {
    return (X) toMultiPoint(((com.here.xyz.models.geojson.implementation.MultiPoint) geometry).getCoordinates());
  }
  if (geometry instanceof com.here.xyz.models.geojson.implementation.LineString) {
    return (X) toLineString(((com.here.xyz.models.geojson.implementation.LineString) geometry).getCoordinates());
  }
  if (geometry instanceof com.here.xyz.models.geojson.implementation.MultiLineString) {
    return (X) toMultiLineString(((com.here.xyz.models.geojson.implementation.MultiLineString) geometry).getCoordinates());
  }
  if (geometry instanceof com.here.xyz.models.geojson.implementation.Polygon) {
    return (X) toPolygon(((com.here.xyz.models.geojson.implementation.Polygon) geometry).getCoordinates());
  }
  if (geometry instanceof com.here.xyz.models.geojson.implementation.MultiPolygon) {
    return (X) toMultiPolygon(((com.here.xyz.models.geojson.implementation.MultiPolygon) geometry).getCoordinates());
  }
  if (geometry instanceof com.here.xyz.models.geojson.implementation.GeometryCollection) {
    return (X) toGeometryCollection(((com.here.xyz.models.geojson.implementation.GeometryCollection) geometry));
  }
  return null;
}
 
Example #21
Source File: MultiLineStringWriter.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Writes the body for a <code>MultiLineString</code> object.
 * MultiLineStrings are encoded into SVG path elements. This function writes
 * the different lines in one d-attribute of an SVG path element, separated
 * by an 'M' character.
 *
 * @param o The <code>MultiLineString</code> to be encoded.
 */
public void writeObject(Object o, GraphicsDocument document, boolean asChild) throws RenderException {
	document.writeElement("vml:shape", asChild);
	document.writeAttributeStart("path");
	MultiLineString ml = (MultiLineString) o;
	for (int i = 0; i < ml.getNumGeometries(); i++) {
		document.writePathContent(ml.getGeometryN(i).getCoordinates());
	}
	document.writeAttributeEnd();
}
 
Example #22
Source File: MultiLineStringWriter.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Writes the body for a <code>MultiLineString</code> object.
 * MultiLineStrings are encoded into SVG path elements. This function writes
 * the different lines in one d-attribute of an SVG path element, separated
 * by an 'M' character.
 *
 * @param o The <code>MultiLineString</code> to be encoded.
 */
public void writeObject(Object o, GraphicsDocument document, boolean asChild) throws RenderException {
	document.writeElement("path", asChild);
	document.writeAttributeStart("d");
	MultiLineString ml = (MultiLineString) o;
	for (int i = 0; i < ml.getNumGeometries(); i++) {
		document.writePathContent(ml.getGeometryN(i).getCoordinates());
	}
	document.writeAttributeEnd();
}
 
Example #23
Source File: DefaultSvgDocument.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
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());
}
 
Example #24
Source File: GeoServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Finish service initialization.
 *
 * @throws GeomajasException oops
 */
@PostConstruct
protected void postConstruct() throws GeomajasException {
	if (null != crsDefinitions) {
		for (CrsInfo crsInfo : crsDefinitions.values()) {
			try {
				CoordinateReferenceSystem crs = CRS.parseWKT(crsInfo.getCrsWkt());
				String code = crsInfo.getKey();
				crsCache.put(code, CrsFactory.getCrs(code, crs));
			} catch (FactoryException e) {
				throw new GeomajasException(e, ExceptionCode.CRS_DECODE_FAILURE_FOR_MAP, crsInfo.getKey());
			}
		}
	}
	if (null != crsTransformDefinitions) {
		for (CrsTransformInfo crsTransformInfo : crsTransformDefinitions.values()) {
			String key = getTransformKey(crsTransformInfo);
			transformCache.put(key, getCrsTransform(key, crsTransformInfo));
		}
	}
	GeometryFactory factory = new GeometryFactory();
	EMPTY_GEOMETRIES.put(Point.class, factory.createPoint((Coordinate) null));
	EMPTY_GEOMETRIES.put(LineString.class, factory.createLineString((Coordinate[]) null));
	EMPTY_GEOMETRIES.put(Polygon.class, factory.createPolygon(null, null));
	EMPTY_GEOMETRIES.put(MultiPoint.class, factory.createMultiPoint((Coordinate[]) null));
	EMPTY_GEOMETRIES.put(MultiLineString.class, factory.createMultiLineString((LineString[]) null)); // cast needed!
	EMPTY_GEOMETRIES.put(MultiPolygon.class, factory.createMultiPolygon((Polygon[]) null)); // cast needed!
	EMPTY_GEOMETRIES.put(Geometry.class, factory.createGeometryCollection(null));
}
 
Example #25
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 transformGeometryEmptyResultOnException() throws Exception {
	GeometryFactory geometryFactory = new GeometryFactory();
	WKTReader reader = new WKTReader( geometryFactory );
	
	Point point = (Point) reader.read("POINT (1 1)");
	Geometry geometry = geoService.transform(point, new ThrowingTransform());
	Assert.assertEquals(Point.class, geometry.getClass());
	Assert.assertTrue(geometry.isEmpty());
	
	LineString lineString = (LineString) reader.read("LINESTRING (0 1,1 1)");
	geometry = geoService.transform(lineString, new ThrowingTransform());
	Assert.assertEquals(LineString.class, geometry.getClass());
	Assert.assertTrue(geometry.isEmpty());
	
	Polygon polygon = (Polygon) reader.read("POLYGON ((0 0,1 1,0 1,0 0))");
	geometry = geoService.transform(polygon, new ThrowingTransform());
	Assert.assertEquals(Polygon.class, geometry.getClass());
	Assert.assertTrue(geometry.isEmpty());

	MultiPoint multipoint = (MultiPoint) reader.read("MULTIPOINT ((1 1),(2 1))");
	geometry = geoService.transform(multipoint, new ThrowingTransform());
	Assert.assertEquals(MultiPoint.class, geometry.getClass());
	Assert.assertTrue(geometry.isEmpty());
	
	MultiLineString multilineString = (MultiLineString) reader.read("MULTILINESTRING ((0 1,1 1),(0 2,2 2))");
	geometry = geoService.transform(multilineString, new ThrowingTransform());
	Assert.assertEquals(MultiLineString.class, geometry.getClass());
	Assert.assertTrue(geometry.isEmpty());
	
	MultiPolygon multipolygon = (MultiPolygon) reader.read("MULTIPOLYGON (((0 0,1 1,0 1,0 0)),((0 0,2 2,0 2,0 0)))");
	geometry = geoService.transform(multipolygon, new ThrowingTransform());
	Assert.assertEquals(MultiPolygon.class, geometry.getClass());
	Assert.assertTrue(geometry.isEmpty());
	
	Geometry collection = (GeometryCollection) reader.read("GEOMETRYCOLLECTION(POINT(4 6),LINESTRING(4 6,7 10)) ");
	geometry = geoService.transform(collection, new ThrowingTransform());
	Assert.assertEquals(GeometryCollection.class, geometry.getClass());
	Assert.assertTrue(geometry.isEmpty());
}
 
Example #26
Source File: GeometryConverterTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
private MultiLineString createJtsMultiLineString() {
	LineString l1 = factory.createLineString(new com.vividsolutions.jts.geom.Coordinate[] { jtsC1, jtsC2, jtsC3,
			jtsC4 });
	LineString l2 = factory.createLineString(new com.vividsolutions.jts.geom.Coordinate[] { jtsC5, jtsC6, jtsC7,
			jtsC8 });
	return factory.createMultiLineString(new LineString[] { l1, l2 });
}
 
Example #27
Source File: DirectionsService.java    From jdal with Apache License 2.0 5 votes vote down vote up
public MultiLineString getRoute(RouteRequest request) {

	try {
		URL url = new URL(serverUrl + "?" + request.toString());
		log.debug("Sending request: " + url.toString());
		return parseResponse(url.getContent());
	} catch (Exception e) {
		log.error(e);
	}
	return null;
}
 
Example #28
Source File: DirectionsService.java    From jdal with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
private MultiLineString parseResponse(Object response) throws IOException {
	
	List<LineString> lines = new ArrayList<LineString>();
	
	String jsonString = responseToString(response);
	JSONObject  json =  JSONObject.fromObject(jsonString);
	
	if ("OK".equals(json.get("status"))) { 
		JSONArray routes = json.getJSONArray("routes");
		JSONArray legs = routes.getJSONObject(0).getJSONArray("legs");
		JSONArray steps = legs.getJSONObject(0).getJSONArray("steps");
		
		if (log.isDebugEnabled())
			log.debug("Get route with " + steps.size() + " steps");
		
		Iterator iter = steps.iterator();
		
		while (iter.hasNext()) {
			JSONObject step = (JSONObject) iter.next();
			String polyline = step.getJSONObject("polyline").getString("points");
			LineString line = decodePolyline(polyline);
			lines.add(line);
		}
	}
	
	return new MultiLineString(lines.toArray(new LineString[] {}), factory);
}
 
Example #29
Source File: StaticMultiLineStringTest.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Round Trip test for a single line string
 * @throws ParserConfigurationException 
 * @throws IOException 
 * @throws SAXException 
 */
public void testSingleMultiLineStringRoundTrip() throws SAXException, IOException, ParserConfigurationException{
	LineStringGenerator pgc = new LineStringGenerator();
	pgc.setGeometryFactory(geometryFactory);
	pgc.setNumberPoints(10);
	MultiGenerator pg = new MultiGenerator(pgc);
	pg.setBoundingBox(new Envelope(0,10,0,10));
	pg.setNumberGeometries(3);
	pg.setGeometryFactory(geometryFactory);
	
	MultiLineString pt = (MultiLineString) pg.create();
	checkRoundTrip(pt);
}
 
Example #30
Source File: JTSHelper.java    From xyz-hub with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a MultiLineString.
 */
public static MultiLineString toMultiLineString(MultiLineStringCoordinates coords) {
  if (coords == null) {
    return null;
  }

  LineString[] lines = new LineString[coords.size()];

  for (int i = 0; i < lines.length; i++) {
    lines[i] = toLineString(coords.get(i));
  }

  return JTSHelper.factory.createMultiLineString(lines);
}