Revision 43909
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.api/src/main/java/org/gvsig/fmap/geom/GeometryManager.java | ||
---|---|---|
790 | 790 |
public Geometry create(String name) throws CreateGeometryException; |
791 | 791 |
|
792 | 792 |
/** |
793 |
* |
|
794 |
* @param data |
|
795 |
* @return |
|
796 |
* @throws CreateGeometryException |
|
797 |
* @throws GeometryException |
|
798 |
*/ |
|
799 |
public Geometry createFrom(Object data) |
|
800 |
throws CreateGeometryException, GeometryException; |
|
801 |
|
|
802 |
/** |
|
793 | 803 |
* Create a geometry from a WKT definition. |
794 | 804 |
* |
795 | 805 |
* This is a utility method to wrap the invocation to the operation |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.api/src/main/java/org/gvsig/fmap/geom/Geometry.java | ||
---|---|---|
482 | 482 |
*/ |
483 | 483 |
public GeometryType getGeometryType(); |
484 | 484 |
|
485 |
public Object convertTo(String format) throws GeometryOperationNotSupportedException, |
|
486 |
GeometryOperationException; |
|
487 |
|
|
485 | 488 |
/** |
486 | 489 |
* Return a byte array with the equivalent in WKB format of the Geometry. |
487 | 490 |
* |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.api/src/main/java/org/gvsig/fmap/geom/GeometryUtils.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.fmap.geom; |
25 | 25 |
|
26 |
import java.util.logging.Level; |
|
27 |
import java.util.logging.Logger; |
|
28 | 26 |
import org.cresques.cts.IProjection; |
29 | 27 |
import org.gvsig.fmap.geom.aggregate.MultiLine; |
30 | 28 |
import org.gvsig.fmap.geom.aggregate.MultiPolygon; |
31 | 29 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
32 | 30 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
33 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
34 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
35 | 31 |
import org.gvsig.fmap.geom.primitive.Envelope; |
36 | 32 |
import org.gvsig.fmap.geom.primitive.Line; |
37 | 33 |
import org.gvsig.fmap.geom.primitive.Point; |
... | ... | |
129 | 125 |
} |
130 | 126 |
} |
131 | 127 |
|
128 |
public static Geometry createFrom(Object data) { |
|
129 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
130 |
try { |
|
131 |
return geomManager.createFrom(data); |
|
132 |
} catch (GeometryException ex) { |
|
133 |
return null; |
|
134 |
} |
|
135 |
} |
|
136 |
|
|
132 | 137 |
public static Geometry createFrom(String wkt, String srs) { |
133 | 138 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
134 | 139 |
try { |
... | ... | |
155 | 160 |
return null; |
156 | 161 |
} |
157 | 162 |
} |
163 |
|
|
164 |
public static Object convertTo(Geometry geom, String format) { |
|
165 |
try { |
|
166 |
return geom.convertTo(format); |
|
167 |
} catch (Exception ex) { |
|
168 |
return null; |
|
169 |
} |
|
170 |
} |
|
158 | 171 |
|
159 | 172 |
public static String toWKT(Geometry geom) { |
160 | 173 |
try { |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.jts/src/main/java/org/gvsig/fmap/geom/jts/util/GMLUtils.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2015 gvSIG Association |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 3 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
18 |
* MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us |
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.fmap.geom.jts.util; |
|
24 |
|
|
25 |
import com.vividsolutions.jts.io.gml2.GMLReader; |
|
26 |
import com.vividsolutions.jts.io.gml2.GMLWriter; |
|
27 |
import org.gvsig.fmap.geom.Geometry; |
|
28 |
import org.gvsig.fmap.geom.jts.GeometryJTS; |
|
29 |
|
|
30 |
/** |
|
31 |
* |
|
32 |
* @author jjdelcerro |
|
33 |
*/ |
|
34 |
public class GMLUtils { |
|
35 |
|
|
36 |
public static Geometry GML2Geometry(String gml) { |
|
37 |
GMLReader reader = new GMLReader(); |
|
38 |
com.vividsolutions.jts.geom.Geometry jtsgeom; |
|
39 |
try { |
|
40 |
jtsgeom = reader.read(gml, null); |
|
41 |
} catch (Exception ex) { |
|
42 |
return null; |
|
43 |
} |
|
44 |
return JTSUtils.createGeometry(jtsgeom); |
|
45 |
} |
|
46 |
|
|
47 |
public static String geometry2GML(Geometry geom) { |
|
48 |
com.vividsolutions.jts.geom.Geometry jtsgeom = ((GeometryJTS) geom).getJTS(); |
|
49 |
|
|
50 |
GMLWriter writer = new GMLWriter(); |
|
51 |
String gml = writer.write(jtsgeom); |
|
52 |
return gml; |
|
53 |
} |
|
54 |
|
|
55 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.jts/src/main/java/org/gvsig/fmap/geom/jts/util/JTSUtils.java | ||
---|---|---|
4 | 4 |
* |
5 | 5 |
* This program is free software; you can redistribute it and/or |
6 | 6 |
* modify it under the terms of the GNU General Public License |
7 |
* as published by the Free Software Foundation; either version 2
|
|
7 |
* as published by the Free Software Foundation; either version 3
|
|
8 | 8 |
* of the License, or (at your option) any later version. |
9 | 9 |
* |
10 | 10 |
* This program is distributed in the hope that it will be useful, |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.jts/src/main/java/org/gvsig/fmap/geom/jts/AbstractGeometry.java | ||
---|---|---|
34 | 34 |
import com.vividsolutions.jts.operation.overlay.snap.GeometrySnapper; |
35 | 35 |
import com.vividsolutions.jts.operation.valid.IsValidOp; |
36 | 36 |
import com.vividsolutions.jts.operation.valid.TopologyValidationError; |
37 |
import org.codehaus.plexus.util.StringUtils; |
|
37 | 38 |
import org.cresques.cts.IProjection; |
38 | 39 |
|
39 | 40 |
import org.slf4j.Logger; |
... | ... | |
49 | 50 |
import org.gvsig.fmap.geom.jts.primitive.Envelope2D; |
50 | 51 |
import org.gvsig.fmap.geom.jts.primitive.Envelope3D; |
51 | 52 |
import org.gvsig.fmap.geom.jts.primitive.point.Point3D; |
53 |
import org.gvsig.fmap.geom.jts.util.GMLUtils; |
|
52 | 54 |
import org.gvsig.fmap.geom.jts.util.JTSUtils; |
53 | 55 |
import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
54 | 56 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
... | ... | |
383 | 385 |
return this.getGeometryType().getType(); |
384 | 386 |
} |
385 | 387 |
|
388 |
@Override |
|
389 |
public Object convertTo(String format) throws GeometryOperationNotSupportedException, GeometryOperationException { |
|
390 |
if( StringUtils.isEmpty(format) ) { |
|
391 |
throw new IllegalArgumentException("Can't accept null as format name."); |
|
392 |
} |
|
393 |
format = format.trim().toLowerCase(); |
|
394 |
switch(format) { |
|
395 |
case "jts": |
|
396 |
return this.getJTS(); |
|
397 |
case "wkb": |
|
398 |
return this.convertToWKB(); |
|
399 |
case "ewkb": |
|
400 |
return this.convertToEWKB(); |
|
401 |
case "wkt": |
|
402 |
return this.convertToWKT(); |
|
403 |
case "gml": |
|
404 |
return GMLUtils.geometry2GML(this); |
|
405 |
case "json": |
|
406 |
case "geojson": |
|
407 |
default: |
|
408 |
throw new IllegalArgumentException("Format '"+format+"' not supported"); |
|
409 |
} |
|
410 |
|
|
411 |
} |
|
412 |
|
|
386 | 413 |
public byte[] convertToWKB() throws GeometryOperationNotSupportedException, GeometryOperationException { |
387 | 414 |
try { |
388 | 415 |
return new OGCWKBEncoder().encode(this); |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.jts/src/main/java/org/gvsig/fmap/geom/jts/DefaultGeometryManager.java | ||
---|---|---|
24 | 24 |
|
25 | 25 |
package org.gvsig.fmap.geom.jts; |
26 | 26 |
|
27 |
import com.vividsolutions.jts.io.gml2.GMLReader; |
|
27 | 28 |
import java.awt.geom.PathIterator; |
28 | 29 |
import java.util.ArrayList; |
29 | 30 |
import java.util.HashMap; |
... | ... | |
57 | 58 |
import org.gvsig.fmap.geom.jts.primitive.Envelope3D; |
58 | 59 |
import org.gvsig.fmap.geom.jts.spatialindex.SpatialIndexFactoryJSIRTree; |
59 | 60 |
import org.gvsig.fmap.geom.jts.spatialindex.SpatialIndexFactoryJTSQuadtree; |
61 |
import org.gvsig.fmap.geom.jts.util.GMLUtils; |
|
60 | 62 |
import org.gvsig.fmap.geom.jts.util.JTSUtils; |
61 | 63 |
import org.gvsig.fmap.geom.operation.GeometryOperation; |
62 | 64 |
import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
... | ... | |
673 | 675 |
this.flatness = flatness; |
674 | 676 |
} |
675 | 677 |
|
678 |
@Override |
|
679 |
public Geometry createFrom(Object data) throws CreateGeometryException, GeometryException { |
|
680 |
if( data == null ) { |
|
681 |
throw new IllegalArgumentException("null data is not allowed"); |
|
682 |
} |
|
683 |
if( data instanceof String ) { |
|
684 |
Geometry geom = GMLUtils.GML2Geometry((String) data); |
|
685 |
if( geom != null ) { |
|
686 |
return geom; |
|
687 |
} |
|
688 |
return this.createFrom((String)data); |
|
689 |
} |
|
690 |
if( data instanceof byte[] ) { |
|
691 |
return this.createFrom((byte[])data); |
|
692 |
} |
|
693 |
if( data instanceof com.vividsolutions.jts.geom.Geometry ) { |
|
694 |
return this.createFrom((com.vividsolutions.jts.geom.Geometry)data); |
|
695 |
} |
|
696 |
if( data instanceof Geometry ) { |
|
697 |
return ((Geometry)data).cloneGeometry(); |
|
698 |
} |
|
699 |
throw new IllegalArgumentException("Type of data ("+data.getClass().getName()+") not supported."); |
|
700 |
} |
|
701 |
|
|
676 | 702 |
public Geometry createFrom(String wkt, String srs) throws GeometryException { |
677 | 703 |
GeometryOperationContext context = new GeometryOperationContext(); |
678 | 704 |
context.setAttribute("text", wkt); |
Also available in: Unified diff