-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2396 from telefonicaid/task/add_esri_geometry_fea…
…ture_support_for_multipoint_polygon add multipoint and polygon esri geometry support for Arcgis features
- Loading branch information
Showing
7 changed files
with
547 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[cygnus-ngsi] [mongo-sink] Add mongo_ssl, mongo_ssl_invalid_host_allowed, mongo_ssl_keystore_path_file, mongo_ssl_keystore_password, mongo_ssl_truststore_path_file and mongo_ssl_truststore_password options for mongoDB connections | ||
[cygnus-common] [mongo-backend] Use sslEnabled, sslInvalidHostNameAllowed, sslKeystorePathFile, sslKeystorePassword, sslTruststorePathFile and sslTruststorePassword options for mongoDB connections | ||
[cygnus-common] [mongo-backend] Allow mongodb autodiscover at connect when just one server is provided | ||
[cygnus-ngsi] [arcgis-sink] Add esri Geometry PolyLine support (#2392) | ||
[cygnus-ngsi] [arcgis-sink] Add esri Geometry PolyLine, MultiPoint and Polygon support (#2392) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
196 changes: 196 additions & 0 deletions
196
cygnus-common/src/main/java/com/telefonica/iot/cygnus/backends/arcgis/model/MultiPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
/** | ||
* Copyright 2014-2017 Telefonica Investigación y Desarrollo, S.A.U | ||
* | ||
* This file is part of fiware-cygnus (FIWARE project). | ||
* | ||
* fiware-cygnus is free software: you can redistribute it and/or modify it under the terms of the GNU Affero | ||
* General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your | ||
* option) any later version. | ||
* fiware-cygnus is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the | ||
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License | ||
* for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License along with fiware-cygnus. If not, see | ||
* http://www.gnu.org/licenses/. | ||
* | ||
* For those usages not covered by the GNU Affero General Public License please contact with iot_support at tid dot es | ||
*/ | ||
|
||
package com.telefonica.iot.cygnus.backends.arcgis.model; | ||
|
||
import java.util.List; | ||
import java.util.Arrays; | ||
import java.util.ArrayList; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
import com.google.gson.Gson; | ||
import com.google.gson.reflect.TypeToken; | ||
import java.lang.reflect.Type; | ||
|
||
import com.telefonica.iot.cygnus.backends.arcgis.exceptions.ArcgisException; | ||
import com.telefonica.iot.cygnus.log.CygnusLogger; | ||
|
||
/** | ||
* | ||
* @author avega | ||
* | ||
*/ | ||
public class MultiPoint implements Geometry { | ||
private static final CygnusLogger LOGGER = new CygnusLogger(MultiPoint.class); | ||
|
||
private static final String SPATIAL_REFERENCE_TAG = "spatialReference"; | ||
private static final String WKID_TAG = "wkid"; | ||
private static final String POINTS_TAG = "points"; | ||
|
||
public List<double[]> points; | ||
|
||
private SpatialReference spatialReference; | ||
private int type = Geometry.TYPE_SHAPE; // TBD | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param points | ||
* @param spatialReference | ||
*/ | ||
public MultiPoint(List<double[]> points, SpatialReference spatialReference) { | ||
this.points = points; | ||
this.spatialReference = spatialReference; | ||
} | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param points | ||
*/ | ||
public MultiPoint(List<double[]> points) { | ||
this(points, SpatialReference.WGS84); | ||
} | ||
|
||
/** | ||
* SetValue. | ||
*/ | ||
public void setValue(Geometry g) throws ArcgisException { | ||
if (g.getGeometryType() == Geometry.TYPE_SHAPE) { | ||
MultiPoint multipoint = (MultiPoint) g; | ||
this.points = multipoint.points; | ||
} else { | ||
throw new ArcgisException("Invalid Geometry Type, MultiPoint expected."); | ||
} | ||
} | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param strPoint | ||
* @throws ArcgisException | ||
*/ | ||
public MultiPoint(String strPolyline) throws ArcgisException { | ||
try { | ||
JsonObject jsonObject = JsonParser.parseString(strPolyline).getAsJsonObject(); | ||
String thePointsStr = jsonObject.get("points").toString(); | ||
Gson gson = new Gson(); | ||
Type listType = new TypeToken<List<double[]>>() {}.getType(); | ||
this.points = gson.fromJson(thePointsStr, listType); | ||
this.spatialReference = SpatialReference.WGS84; | ||
} catch (NumberFormatException e) { | ||
LOGGER.error(e.getClass().getSimpleName() + " " + e.getMessage()); | ||
throw new ArcgisException("Unexpected string format for type MultiPoint."); | ||
} | ||
} | ||
|
||
/** | ||
* Sets Geometry From JSON. | ||
*/ | ||
public void setGeometryFromJSON(String json) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
/** | ||
* @return JsonObject | ||
*/ | ||
public JsonObject toJSON() { | ||
JsonObject result = new JsonObject(); | ||
LOGGER.debug("toJSON "); | ||
result.addProperty(POINTS_TAG, this.toString()); | ||
|
||
JsonObject spatialRef = new JsonObject(); | ||
spatialRef.addProperty(WKID_TAG, spatialReference.getWkid()); | ||
|
||
result.add(SPATIAL_REFERENCE_TAG, spatialRef); | ||
return result; | ||
} | ||
|
||
/** | ||
* Factroy method. | ||
* | ||
* @param json | ||
* @return | ||
* @throws ArcgisException | ||
*/ | ||
public static Geometry createInstanceFromJson(JsonObject json) throws ArcgisException { | ||
try { | ||
return new MultiPoint(json.get(POINTS_TAG).getAsString()); | ||
} catch (Exception e) { | ||
LOGGER.error(e.getClass().getSimpleName() + " " + e.getMessage()); | ||
throw new ArcgisException("Unable to parse MultiPoint from json " + e.getMessage()); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* @return String | ||
*/ | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("{ \"points\": ["); | ||
for (int i = 0; i < this.points.size(); i++) { | ||
sb.append("["); | ||
double[] array = points.get(i); | ||
for (double value : array) { | ||
sb.append(" ").append(value).append(","); | ||
} | ||
sb.setLength(sb.length() - 2); | ||
sb.append(" ],"); | ||
} | ||
sb.setLength(sb.length() - 2); | ||
sb.append(" ]}"); | ||
return sb.toString(); | ||
} | ||
|
||
/** | ||
* @return geometry type | ||
*/ | ||
public int getGeometryType() { | ||
return type; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public void setSpatialReference(SpatialReference spatialReference) { | ||
this.spatialReference = spatialReference; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public SpatialReference getSpatialReference() { | ||
return this.spatialReference; | ||
} | ||
|
||
/** | ||
* | ||
* @return | ||
*/ | ||
public List<double[]> getPoints() { | ||
return this.points; | ||
} | ||
|
||
@Override | ||
public Object getValue() { | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.