com.vividsolutions.jts.geom.LineString Java Examples
The following examples show how to use
com.vividsolutions.jts.geom.LineString.
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: GeoWaveIndexerSfTest.java From rya with Apache License 2.0 | 6 votes |
/** * 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); } }
Example #2
Source File: MultiPolygonWriter.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
/** * Writes the body for a <code>MultiPolygon</code> object. MultiPolygons are * encoded into SVG path elements. This function writes the different * polygons in one d-attribute of an SVG path element, separated by an 'M' * character. (in other words, it calls the super.writeBody for each * polygon). * * @param o The <code>MultiPolygon</code> to be encoded. */ public void writeObject(Object o, GraphicsDocument document, boolean asChild) throws RenderException { document.writeElement("vml:shape", asChild); document.writeAttribute("fill-rule", "evenodd"); document.writeAttributeStart("path"); MultiPolygon mpoly = (MultiPolygon) o; for (int i = 0; i < mpoly.getNumGeometries(); i++) { Polygon poly = (Polygon) mpoly.getGeometryN(i); LineString shell = poly.getExteriorRing(); int nHoles = poly.getNumInteriorRing(); document.writeClosedPathContent(shell.getCoordinates()); for (int j = 0; j < nHoles; j++) { document.writeClosedPathContent(poly.getInteriorRingN(j).getCoordinates()); } } document.writeAttributeEnd(); }
Example #3
Source File: PolygonConverter.java From game-server with MIT License | 6 votes |
/** * 生成KPolygon * @param lineString * @return */ public KPolygon makeKPolygonFrom(com.vividsolutions.jts.geom.LineString lineString) { CoordinateSequence coordinateSequence = lineString.getCoordinateSequence(); ArrayList<Vector3> points = new ArrayList<>(); // The loop stops at the second-last coord since the last coord will be // the same as the start coord. Vector3 lastAddedPoint = null; for (int i = 0; i < coordinateSequence.size() - 1; i++) { Coordinate coord = coordinateSequence.getCoordinate(i); Vector3 p = new Vector3((float)coord.x, (float)coord.z, (float)coord.y); if (lastAddedPoint != null && p.x == lastAddedPoint.x && p.z == lastAddedPoint.z) { // Don't add the point since it's the same as the last one continue; } else { points.add(p); lastAddedPoint = p; } } if (points.size() < 3) { return null; } KPolygon polygon = new KPolygon(points); return polygon; }
Example #4
Source File: BaseLineStringBuilder.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public Shape build() { Coordinate[] coordinates = points.toArray(new Coordinate[points.size()]); Geometry geometry; if(wrapdateline) { ArrayList<LineString> strings = decompose(FACTORY, coordinates, new ArrayList<LineString>()); if(strings.size() == 1) { geometry = strings.get(0); } else { LineString[] linestrings = strings.toArray(new LineString[strings.size()]); geometry = FACTORY.createMultiLineString(linestrings); } } else { geometry = FACTORY.createLineString(coordinates); } return jtsGeometry(geometry); }
Example #5
Source File: OraReaderCreateTest.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
public void testRawLineStringM2() throws Exception { final GeometryFactory geometryFactory = new GeometryFactory(); final OraReader oraReader = new OraReader(geometryFactory); // Geometry type is a 3-dimensional measured line. final int gType = 3302; // The 'line' is starting at ordinate offset 1. final int[] elemInfo = new int[] {1, 2, 1}; final double[] ordinates = new double[] {1, 1, 20, 2, 2, 30}; // Made 'create' method package private to enable test. final Geometry actual = oraReader.read(new OraGeom(gType, 0, elemInfo, ordinates)); // Preparing expected result. final LineString expected = geometryFactory.createLineString(new Coordinate[] {new Coordinate(1, 1), new Coordinate(2, 2)}); assertEquals(expected, actual); }
Example #6
Source File: LayerTypeConverterTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
@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 #7
Source File: OraGeom.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
/** * 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 #8
Source File: AllowedAttributeTypes.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * 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 #9
Source File: WKTWriter.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
/** * Converts a <code>LineString</code> to <LineString Text> format, then * appends it to the writer. * *@param lineString the <code>LineString</code> to process *@param writer the output writer to append to */ private void appendLineStringText(LineString lineString, int level, boolean doIndent, Writer writer) throws IOException { if (lineString.isEmpty()) { writer.write("EMPTY"); } else { if (doIndent) indent(level, writer); writer.write("("); for (int i = 0; i < lineString.getNumPoints(); i++) { if (i > 0) { writer.write(", "); if (coordsPerLine > 0 && i % coordsPerLine == 0) { indent(level + 1, writer); } } appendCoordinate(lineString.getCoordinateN(i), writer); } writer.write(")"); } }
Example #10
Source File: VariableWidthBuffer.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
/** * Computes a list of values for the points along a line by * interpolating between values for the start and end point. * The interpolation is * based on the distance of each point along the line * relative to the total line length. * * @param line the line to interpolate along * @param start the start value * @param end the end value * @return the array of interpolated values */ public static double[] interpolate(LineString line, double start, double end) { start = Math.abs(start); end = Math.abs(end); double[] widths = new double[line.getNumPoints()]; widths[0] = start; widths[widths.length - 1] = end; double totalLen = line.getLength(); Coordinate[] pts = line.getCoordinates(); double currLen = 0; for (int i = 1; i < widths.length; i++) { double segLen = pts[i].distance(pts[i - 1]); currLen += segLen; double lenFrac = currLen / totalLen; double delta = lenFrac * (end - start); widths[i] = start + delta; } return widths; }
Example #11
Source File: JTSModel.java From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void addOSMOpenWays(OSMDataSet ds) { List<OSMWay> openWays = ds.getOpenWays(); for (OSMWay w : openWays) { if (!w.isModified() && OSMWay.containsModifiedWay(w.getId())) { continue; } // Don't render or index ways that do not have all of their referenced nodes. if (w.incomplete()) { continue; } List<OSMNode> nodes = w.getNodes(); Coordinate[] coords = coordArrayFromNodeList(nodes); LineString line = geometryFactory.createLineString(coords); w.setJTSGeom(line); Envelope envelope = line.getEnvelopeInternal(); spatialIndex.insert(envelope, w); } }
Example #12
Source File: GamaShape.java From gama with GNU General Public License v3.0 | 6 votes |
@Override public GamaShape getExteriorRing(final IScope scope) { // WARNING Only in 2D Geometry result = getInnerGeometry(); if (result instanceof Polygon) { result = ((Polygon) result).getExteriorRing(); } else if (result instanceof MultiPolygon) { final MultiPolygon mp = (MultiPolygon) result; final LineString lines[] = new LineString[mp.getNumGeometries()]; for (int i = 0; i < mp.getNumGeometries(); i++) { lines[i] = ((Polygon) mp.getGeometryN(i)).getExteriorRing(); } result = GEOMETRY_FACTORY.createMultiLineString(lines); } return new GamaShape(result); }
Example #13
Source File: KMLWriter.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
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()); }
Example #14
Source File: GamaSpatialPath.java From gama with GNU General Public License v3.0 | 6 votes |
protected double zVal(final GamaPoint point, final IShape edge) { double z = 0.0; final int nbSp = getPointsOf(edge).length; final Coordinate[] temp = new Coordinate[2]; final Point pointGeom = (Point) point.getInnerGeometry(); double distanceS = Double.MAX_VALUE; final GamaPoint[] edgePoints = GeometryUtils.getPointsOf(edge); for (int i = 0; i < nbSp - 1; i++) { temp[0] = edgePoints[i]; temp[1] = edgePoints[i + 1]; final LineString segment = GeometryUtils.GEOMETRY_FACTORY.createLineString(temp); final double distS = segment.distance(pointGeom); if (distS < distanceS) { distanceS = distS; final GamaPoint pt0 = new GamaPoint(temp[0]); final GamaPoint pt1 = new GamaPoint(temp[1]); z = pt0.z + (pt1.z - pt0.z) * point.distance(pt0) / segment.getLength(); } } return z; }
Example #15
Source File: Main.java From chuidiang-ejemplos with GNU Lesser General Public License v3.0 | 6 votes |
private static void updateGeometry(SessionFactory sessionFactory) { Session session = sessionFactory.openSession(); session.beginTransaction(); TheData theData = session.get(TheData.class, 1L); LineString geometry = geometryFactory.createLineString(new Coordinate[]{ new Coordinate(5,6), new Coordinate(7,8), new Coordinate(9,10)}); theData.setTheGeometry(geometry); session.saveOrUpdate(theData); session.getTransaction().commit(); session.close(); }
Example #16
Source File: GeometryUtils.java From gama with GNU General Public License v3.0 | 6 votes |
public static Coordinate[] extractPoints(final IShape triangle1, final IShape triangle2) { final Coordinate[] coords = triangle1.getInnerGeometry().getCoordinates(); final Coordinate[] c1 = { coords[0], coords[1] }; final Coordinate[] c2 = { coords[1], coords[2] }; final Coordinate[] c3 = { coords[2], coords[3] }; final LineString l1 = GEOMETRY_FACTORY.createLineString(c1); final LineString l2 = GEOMETRY_FACTORY.createLineString(c2); final LineString l3 = GEOMETRY_FACTORY.createLineString(c3); final Coordinate[] pts = new Coordinate[3]; if (nbCommonPoints(l1, triangle2.getInnerGeometry()) == 2) { pts[1] = l1.getCentroid().getCoordinate(); } else if (nbCommonPoints(l2, triangle2.getInnerGeometry()) == 2) { pts[1] = l2.getCentroid().getCoordinate(); } else if (nbCommonPoints(l3, triangle2.getInnerGeometry()) == 2) { pts[1] = l3.getCentroid().getCoordinate(); } pts[0] = triangle1.getCentroid(); pts[2] = triangle2.getCentroid(); return pts; }
Example #17
Source File: GeometryConverterTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
@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 #18
Source File: Distance3DOp.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
private void computeMinDistanceLineLine(LineString line0, LineString line1, boolean flip) { Coordinate[] coord0 = line0.getCoordinates(); Coordinate[] coord1 = line1.getCoordinates(); // brute force approach! for (int i = 0; i < coord0.length - 1; i++) { for (int j = 0; j < coord1.length - 1; j++) { double dist = CGAlgorithms3D.distanceSegmentSegment(coord0[i], coord0[i + 1], coord1[j], coord1[j + 1]); if (dist < minDistance) { minDistance = dist; // TODO: compute closest pts in 3D LineSegment seg0 = new LineSegment(coord0[i], coord0[i + 1]); LineSegment seg1 = new LineSegment(coord1[j], coord1[j + 1]); Coordinate[] closestPt = seg0.closestPoints(seg1); updateDistance(dist, new GeometryLocation(line0, i, closestPt[0]), new GeometryLocation(line1, j, closestPt[1]), flip ); } if (isDone) return; } } }
Example #19
Source File: GeoIndexerSfTest.java From rya with Apache License 2.0 | 6 votes |
/** * 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); } }
Example #20
Source File: DirectionsService.java From jdal with Apache License 2.0 | 5 votes |
private LineString decodePolyline(String encoded) { List<Coordinate> coordinates = new ArrayList<Coordinate>(); int index = 0, len = encoded.length(); int lat = 0, lng = 0; while (index < len) { int b, shift = 0, result = 0; do { b = encoded.charAt(index++) - 63; result |= (b & 0x1f) << shift; shift += 5; } while (b >= 0x20); int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); lat += dlat; shift = 0; result = 0; do { b = encoded.charAt(index++) - 63; result |= (b & 0x1f) << shift; shift += 5; } while (b >= 0x20); int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); lng += dlng; coordinates.add(new Coordinate(lat/1E5, lng/1E5 )); } return new LineString(new CoordinateArraySequence(coordinates.toArray(new Coordinate[] {})), factory); }
Example #21
Source File: MiscellaneousTest.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
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 #22
Source File: StyleConverterServiceImpl.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
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 #23
Source File: LineDissolver.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
/** * Adds a {@link Geometry} to be dissolved. * Any number of geometries may be adde by calling this method multiple times. * Any type of Geometry may be added. The constituent linework will be * extracted to be dissolved. * * @param geometry geometry to be line-merged */ public void add(Geometry geometry) { geometry.apply(new GeometryComponentFilter() { public void filter(Geometry component) { if (component instanceof LineString) { add((LineString)component); } } }); }
Example #24
Source File: SegmentStringUtil.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
/** * Extracts all linear components from a given {@link Geometry} * to {@link SegmentString}s. * The SegmentString data item is set to be the source Geometry. * * @param geom the geometry to extract from * @return a List of SegmentStrings */ public static List extractNodedSegmentStrings(Geometry geom) { List segStr = new ArrayList(); List lines = LinearComponentExtracter.getLines(geom); for (Iterator i = lines.iterator(); i.hasNext(); ) { LineString line = (LineString) i.next(); Coordinate[] pts = line.getCoordinates(); segStr.add(new NodedSegmentString(pts, geom)); } return segStr; }
Example #25
Source File: WKTWriterTest.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public void testWriteLineString() { Coordinate[] coordinates = { new Coordinate(10, 10, 0), new Coordinate(20, 20, 0), new Coordinate(30, 40, 0) }; LineString lineString = geometryFactory.createLineString(coordinates); assertEquals("LINESTRING (10 10, 20 20, 30 40)", writer.write(lineString).toString()); }
Example #26
Source File: GeoIndexerSfTest.java From rya with Apache License 2.0 | 5 votes |
/** * convert a lineString geometry to GML * @param line * @return String that is XML that is a GMLLiteral of line */ private static String geoToGml(final LineString line) { final StringBuilder coordString = new StringBuilder() ; for (final Coordinate coor : line.getCoordinates()) { coordString.append(" ").append(coor.x).append(" ").append(coor.y); //ESPG:4326 lat/long } return " <gml:LineString srsName=\"http://www.opengis.net/def/crs/EPSG/0/4326\" xmlns:gml='http://www.opengis.net/gml'>\n" + "<gml:posList srsDimension=\"2\">"// + coordString // + "</gml:posList></gml:LineString >"; }
Example #27
Source File: DefaultVmlDocument.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
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 #28
Source File: PolygonWriter.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
/** * Writes the object to the specified document, optionally creating a child * element. The object in this case should be a polygon. * * @param o the object (of type Polygon). * @param document the document to write to. * @param asChild create child element if true. * @throws RenderException */ public void writeObject(Object o, GraphicsDocument document, boolean asChild) throws RenderException { document.writeElement("vml:shape", asChild); document.writeAttributeStart("path"); Polygon poly = (Polygon) o; LineString shell = poly.getExteriorRing(); int nHoles = poly.getNumInteriorRing(); document.writeClosedPathContent(shell.getCoordinates()); for (int j = 0; j < nHoles; j++) { document.writeClosedPathContent(poly.getInteriorRingN(j).getCoordinates()); } document.writeAttributeEnd(); }
Example #29
Source File: OraReader.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
/** * Create LineString as encoded. * * @param oraGeom SDO_GEOMETRY attributes being read * @param elemIndex the element being read * @param coords the coordinates of the entire geometry * @return LineString * * @throws IllegalArgumentException If asked to create a curve */ private LineString readLine(OraGeom oraGeom, int elemIndex) { int etype = oraGeom.eType(elemIndex); int interpretation = oraGeom.interpretation(elemIndex); checkOrdinates(oraGeom, elemIndex, "LineString"); checkETYPE(etype, OraGeom.ETYPE.LINE, "LineString"); checkInterpretation(interpretation, OraGeom.INTERP.LINESTRING, "LineString"); LineString line = geometryFactory.createLineString( extractCoords(oraGeom, elemIndex)); return line; }
Example #30
Source File: GeoWaveIndexerSfTest.java From rya with Apache License 2.0 | 5 votes |
/** * convert a lineString geometry to GML * @param line * @return String that is XML that is a GMLLiteral of line */ private static String geoToGml(final LineString line) { final StringBuilder coordString = new StringBuilder() ; for (final Coordinate coor : line.getCoordinates()) { coordString.append(" ").append(coor.x).append(" ").append(coor.y); //ESPG:4326 lat/long } return " <gml:LineString srsName=\"http://www.opengis.net/def/crs/EPSG/0/4326\" xmlns:gml='http://www.opengis.net/gml'>\n" + "<gml:posList srsDimension=\"2\">"// + coordString // + "</gml:posList></gml:LineString >"; }