Java Code Examples for com.vividsolutions.jts.geom.MultiLineString

The following examples show how to use com.vividsolutions.jts.geom.MultiLineString. These examples are extracted from open source projects. 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
/**
 * 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 2
Source Project: gama   Source File: GamaKmlExport.java    License: 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 3
Source Project: gama   Source File: SaveStatement.java    License: 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 4
Source Project: jts   Source File: OraGeom.java    License: 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 5
Source Project: jts   Source File: WKBWriter.java    License: 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 6
Source Project: jts   Source File: WKTWriter.java    License: 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 7
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 8
/**
 * 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 9
/**
 * 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 10
@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 11
@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 12
@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 13
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 14
Source Project: xyz-hub   Source File: JTSHelper.java    License: 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);
}
 
Example 15
Source Project: xyz-hub   Source File: JTSHelper.java    License: 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 16
Source Project: xyz-hub   Source File: JTSHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create GeoJSON MultiLineString coordinates.
 */
public static MultiLineStringCoordinates createMultiLineStringCoordinates(MultiLineString geom) {
  if (geom == null) {
    return null;
  }

  int len = geom.getNumGeometries();
  MultiLineStringCoordinates multiLineStringCoordinates = new MultiLineStringCoordinates(len);

  for (int i = 0; i < len; i++) {
    multiLineStringCoordinates.add(createLineStringCoordinates((LineString) geom.getGeometryN(i)));
  }

  return multiLineStringCoordinates;
}
 
Example 17
Source Project: xyz-hub   Source File: JTSHelper.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 18
/**
 * 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);
}
 
Example 19
Source Project: gama   Source File: SLDs.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static final boolean isLine(final SimpleFeatureType featureType) {
	if (featureType == null) { return false; }
	final GeometryDescriptor geometryType = featureType.getGeometryDescriptor();
	if (geometryType == null) { return false; }
	final Class<?> type = geometryType.getType().getBinding();
	return LineString.class.isAssignableFrom(type) || MultiLineString.class.isAssignableFrom(type);
}
 
Example 20
Source Project: gama   Source File: Utils.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a default Style ofr the featureSource.
 *
 * @param featureSource
 *            the source on which to create the style.
 * @return the style created.
 */
public static Style createStyle2(final SimpleFeatureSource featureSource) {
	final SimpleFeatureType schema = featureSource.getSchema();
	final Class<?> geomType = schema.getGeometryDescriptor().getType().getBinding();

	if (Polygon.class.isAssignableFrom(geomType) || MultiPolygon.class.isAssignableFrom(geomType)) {
		return createPolygonStyle();

	} else if (LineString.class.isAssignableFrom(geomType) || MultiLineString.class.isAssignableFrom(geomType)) {
		return createLineStyle();

	} else {
		return createPointStyle();
	}
}
 
Example 21
Source Project: gama   Source File: GamaKmlExport.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void addMultiLine(final Placemark pm, final MultiLineString mline, final double height) {
	final int ng = mline.getNumGeometries();
	final MultiGeometry mg = pm.createAndSetMultiGeometry();
	for (int gx = 0; gx < ng; gx++) {
		final de.micromata.opengis.kml.v_2_2_0.LineString kmlline = mg.createAndAddLineString();
		fillLine(kmlline, (LineString) mline.getGeometryN(gx), height);
	}
}
 
Example 22
Source Project: jts   Source File: GMLReaderTestCase.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testMultiLineStringRead() throws SAXException, IOException, ParserConfigurationException{
	Reader fr = TestFiles.getReader(TestFiles.GML_DIR + "multilinestrings.xml");
	
	GMLReader gr = new GMLReader();
	Geometry g = gr.read(fr,geometryFactory);
	
	GeometryCollection gc = (GeometryCollection)g;
	assertTrue(gc.getNumGeometries() == 25);
	
	for(int i=0;i<25;i++){
		MultiLineString ls = (MultiLineString) gc.getGeometryN(i);
		assertNotNull(ls);
	}
}
 
Example 23
/**
 * 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 24
/**
 * Round Trip test for a single line string with lotsa points
 * @throws IOException 
 * @throws ParserConfigurationException 
 * @throws SAXException 
 */
public void testSingleMultiLineStringManyPointRoundTrip() throws IOException, SAXException, ParserConfigurationException{

	LineStringGenerator pgc = new LineStringGenerator();
	pgc.setGeometryFactory(geometryFactory);
	pgc.setNumberPoints(1000);
	pgc.setGenerationAlgorithm(LineStringGenerator.HORZ);
	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 25
Source Project: jts   Source File: OraReader.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Create MultiLineString as encoded by elemInfo.
 *
 * @param oraGeom SDO_GEOMETRY attributes being read
 * @param coords the coordinates of the entire geometry
 * @return MultiLineString
 */
private MultiLineString readMultiLine(OraGeom oraGeom) 
{
  int nElem = oraGeom.numElements();
  List geoms = new ArrayList();
  for (int i = 0; i < nElem; i++) {
    int etype = oraGeom.eType(i);
    // stop reading if not a line
    if (etype != OraGeom.ETYPE.LINE)
      break;
    geoms.add(readLine(oraGeom, i));
  }
  MultiLineString lines = geometryFactory.createMultiLineString(GeometryFactory.toLineStringArray(geoms));
  return lines;
}
 
Example 26
Source Project: jts   Source File: WKTWriter.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 *  Converts a <code>Geometry</code> to &lt;Geometry Tagged Text&gt; format,
 *  then appends it to the writer.
 *
 *@param  geometry  the <code>Geometry</code> to process
 *@param  writer    the output writer to append to
 */
private void appendGeometryTaggedText(Geometry geometry, int level, Writer writer)
  throws IOException
{
  indent(level, writer);

  if (geometry instanceof Point) {
    Point point = (Point) geometry;
    appendPointTaggedText(point.getCoordinate(), level, writer, point.getPrecisionModel());
  }
  else if (geometry instanceof LinearRing) {
    appendLinearRingTaggedText((LinearRing) geometry, level, writer);
  }
  else if (geometry instanceof LineString) {
    appendLineStringTaggedText((LineString) geometry, level, writer);
  }
  else if (geometry instanceof Polygon) {
    appendPolygonTaggedText((Polygon) geometry, level, writer);
  }
  else if (geometry instanceof MultiPoint) {
    appendMultiPointTaggedText((MultiPoint) geometry, level, writer);
  }
  else if (geometry instanceof MultiLineString) {
    appendMultiLineStringTaggedText((MultiLineString) geometry, level, writer);
  }
  else if (geometry instanceof MultiPolygon) {
    appendMultiPolygonTaggedText((MultiPolygon) geometry, level, writer);
  }
  else if (geometry instanceof GeometryCollection) {
    appendGeometryCollectionTaggedText((GeometryCollection) geometry, level, writer);
  }
  else {
    Assert.shouldNeverReachHere("Unsupported Geometry implementation:"
         + geometry.getClass());
  }
}
 
Example 27
Source Project: jts   Source File: WKTWriter.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 *  Converts a <code>MultiLineString</code> to &lt;MultiLineString Tagged
 *  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 appendMultiLineStringTaggedText(MultiLineString multiLineString, int level,
    Writer writer)
  throws IOException
{
  writer.write("MULTILINESTRING ");
  appendMultiLineStringText(multiLineString, level, false, writer);
}
 
Example 28
Source Project: jts   Source File: WKTWriterTest.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testWriteMultiLineString() {
  Coordinate[] coordinates1 = { new Coordinate(10, 10, 0),
                                new Coordinate(20, 20, 0) };
  LineString lineString1 = geometryFactory.createLineString(coordinates1);
  Coordinate[] coordinates2 = { new Coordinate(15, 15, 0),
                                new Coordinate(30, 15, 0) };
  LineString lineString2 = geometryFactory.createLineString(coordinates2);
  LineString[] lineStrings = {lineString1, lineString2};
  MultiLineString multiLineString = geometryFactory.createMultiLineString(lineStrings);
  assertEquals("MULTILINESTRING ((10 10, 20 20), (15 15, 30 15))", writer.write(multiLineString).toString());
}
 
Example 29
Source Project: jts   Source File: MiscellaneousTest.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testBoundaryOfEmptyGeometry() throws Exception {
  assertTrue(geometryFactory.createPoint((Coordinate)null).getBoundary().getClass() == GeometryCollection.class);
  assertTrue(geometryFactory.createLinearRing(new Coordinate[] { }).getBoundary().getClass() == MultiPoint.class);
  assertTrue(geometryFactory.createLineString(new Coordinate[] { }).getBoundary().getClass() == MultiPoint.class);
  assertTrue(geometryFactory.createPolygon(geometryFactory.createLinearRing(new Coordinate[] { }), new LinearRing[] { }).getBoundary().getClass() == MultiLineString.class);
  assertTrue(geometryFactory.createMultiPolygon(new Polygon[] { }).getBoundary().getClass() == MultiLineString.class);
  assertTrue(geometryFactory.createMultiLineString(new LineString[] { }).getBoundary().getClass() == MultiPoint.class);
  assertTrue(geometryFactory.createMultiPoint(new Point[] { }).getBoundary().getClass() == GeometryCollection.class);
  try {
    geometryFactory.createGeometryCollection(new Geometry[] { }).getBoundary();
    assertTrue(false);
  }
  catch (IllegalArgumentException e) {
  }
}
 
Example 30
Source Project: jts   Source File: MiscellaneousTest.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testEmptyMultiLineString() throws Exception {
    MultiLineString g = geometryFactory.createMultiLineString(null);
    assertEquals(1, g.getDimension());
    assertEquals(new Envelope(), g.getEnvelopeInternal());
/**
 * @todo Enable when #isSimple implemented
 */
//    assertTrue(g.isSimple());
    assertTrue(! g.isClosed());
  }