Revision 46618
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/DefaultGeometryLibrary.java | ||
---|---|---|
49 | 49 |
import org.gvsig.fmap.geom.jts.coerce.CoerceToGeometry; |
50 | 50 |
import org.gvsig.fmap.geom.jts.coerce.CoerceToString; |
51 | 51 |
import org.gvsig.fmap.geom.jts.complex.DefaultComplex; |
52 |
import org.gvsig.fmap.geom.jts.json.EnvelopeJsonSerializer; |
|
53 |
import org.gvsig.fmap.geom.jts.json.GeometryJsonSerializer; |
|
52 | 54 |
import org.gvsig.fmap.geom.jts.json.GeometryTypeJsonSerializer; |
53 | 55 |
import org.gvsig.fmap.geom.jts.operation.fromjts.FromJTS; |
54 | 56 |
import org.gvsig.fmap.geom.jts.operation.fromwkb.FromPostGISEWKB; |
... | ... | |
298 | 300 |
geometryManager.registerGeometryOperation(FromWKT.NAME, new FromWKT()); |
299 | 301 |
|
300 | 302 |
Json.registerSerializer(new GeometryTypeJsonSerializer()); |
303 |
Json.registerSerializer(new GeometryJsonSerializer()); |
|
304 |
Json.registerSerializer(new EnvelopeJsonSerializer()); |
|
301 | 305 |
} |
302 | 306 |
} |
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/json/EnvelopeJsonSerializer.java | ||
---|---|---|
1 |
/* |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2020 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
18 |
* |
|
19 |
* For any additional information, do not hesitate to contact us |
|
20 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
21 |
*/ |
|
22 |
|
|
23 |
package org.gvsig.fmap.geom.jts.json; |
|
24 |
|
|
25 |
import javax.json.JsonObject; |
|
26 |
import org.apache.commons.lang3.StringUtils; |
|
27 |
import org.gvsig.fmap.geom.Geometry; |
|
28 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
29 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
30 |
import org.gvsig.json.Json; |
|
31 |
import org.gvsig.json.JsonManager; |
|
32 |
import org.gvsig.json.JsonObjectBuilder; |
|
33 |
import org.gvsig.tools.util.IsApplicable; |
|
34 |
|
|
35 |
/** |
|
36 |
* |
|
37 |
* @author gvSIG Team |
|
38 |
*/ |
|
39 |
@SuppressWarnings("UseSpecificCatch") |
|
40 |
public class EnvelopeJsonSerializer implements JsonManager.JsonSerializer, IsApplicable { |
|
41 |
|
|
42 |
@Override |
|
43 |
public Class getObjectClass() { |
|
44 |
return Envelope.class; |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
48 |
public Object toObject(JsonObject json) { |
|
49 |
try { |
|
50 |
String wkt = json.getString("wkt"); |
|
51 |
Geometry geom = GeometryLocator.getGeometryManager().createFrom(wkt); |
|
52 |
return geom.getEnvelope(); |
|
53 |
} catch (Exception ex) { |
|
54 |
throw new IllegalArgumentException("Can't retrieve a Envelope from JsonObject.", ex); |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
public JsonObjectBuilder toJsonBuilder(Object value) { |
|
60 |
JsonObjectBuilder builder = Json.createObjectBuilder(); |
|
61 |
builder.add_class(Envelope.class); |
|
62 |
this.addAll(builder, value); |
|
63 |
return builder; |
|
64 |
} |
|
65 |
|
|
66 |
private void addAll(JsonObjectBuilder target, Object source) { |
|
67 |
Envelope env = (Envelope) source; |
|
68 |
Geometry geom = env.getGeometry(); |
|
69 |
target.add("wkt", geom.convertToWKTQuietly()); |
|
70 |
} |
|
71 |
|
|
72 |
@Override |
|
73 |
public boolean isApplicable(Object... args) { |
|
74 |
if( args[0] instanceof Envelope) { |
|
75 |
return true; |
|
76 |
} |
|
77 |
if( !(args[0] instanceof JsonObject) ) { |
|
78 |
return false; |
|
79 |
} |
|
80 |
JsonObject json = (JsonObject) args[0]; |
|
81 |
String className = json.getString(JsonManager.ATTRIBUTE_NAME_CLASS, null); |
|
82 |
return StringUtils.equalsIgnoreCase(className, Envelope.class.getName()); |
|
83 |
} |
|
84 |
|
|
85 |
} |
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/json/GeometryJsonSerializer.java | ||
---|---|---|
1 |
/* |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2020 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
18 |
* |
|
19 |
* For any additional information, do not hesitate to contact us |
|
20 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
21 |
*/ |
|
22 |
|
|
23 |
package org.gvsig.fmap.geom.jts.json; |
|
24 |
|
|
25 |
import javax.json.JsonObject; |
|
26 |
import org.apache.commons.lang3.StringUtils; |
|
27 |
import org.gvsig.fmap.geom.Geometry; |
|
28 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
29 |
import org.gvsig.json.Json; |
|
30 |
import org.gvsig.json.JsonManager; |
|
31 |
import org.gvsig.json.JsonObjectBuilder; |
|
32 |
import org.gvsig.tools.util.IsApplicable; |
|
33 |
|
|
34 |
/** |
|
35 |
* |
|
36 |
* @author gvSIG Team |
|
37 |
*/ |
|
38 |
@SuppressWarnings("UseSpecificCatch") |
|
39 |
public class GeometryJsonSerializer implements JsonManager.JsonSerializer, IsApplicable { |
|
40 |
|
|
41 |
@Override |
|
42 |
public Class getObjectClass() { |
|
43 |
return Geometry.class; |
|
44 |
} |
|
45 |
|
|
46 |
@Override |
|
47 |
public Object toObject(JsonObject json) { |
|
48 |
try { |
|
49 |
String wkt = json.getString("wkt"); |
|
50 |
Geometry geom = GeometryLocator.getGeometryManager().createFrom(wkt); |
|
51 |
return geom; |
|
52 |
} catch (Exception ex) { |
|
53 |
throw new IllegalArgumentException("Can't retrieve a Geometry from JsonObject.", ex); |
|
54 |
} |
|
55 |
} |
|
56 |
|
|
57 |
@Override |
|
58 |
public JsonObjectBuilder toJsonBuilder(Object value) { |
|
59 |
JsonObjectBuilder builder = Json.createObjectBuilder(); |
|
60 |
builder.add_class(Geometry.class); |
|
61 |
this.addAll(builder, value); |
|
62 |
return builder; |
|
63 |
} |
|
64 |
|
|
65 |
private void addAll(JsonObjectBuilder target, Object source) { |
|
66 |
Geometry geom = (Geometry) source; |
|
67 |
target.add("wkt", geom.convertToWKTQuietly()); |
|
68 |
} |
|
69 |
|
|
70 |
@Override |
|
71 |
public boolean isApplicable(Object... args) { |
|
72 |
if( args[0] instanceof Geometry) { |
|
73 |
return true; |
|
74 |
} |
|
75 |
if( !(args[0] instanceof JsonObject) ) { |
|
76 |
return false; |
|
77 |
} |
|
78 |
JsonObject json = (JsonObject) args[0]; |
|
79 |
String className = json.getString(JsonManager.ATTRIBUTE_NAME_CLASS, null); |
|
80 |
return StringUtils.equalsIgnoreCase(className, Geometry.class.getName()); |
|
81 |
} |
|
82 |
|
|
83 |
} |
Also available in: Unified diff