-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add esri Geometry PolyLine support for Arcgis #2394
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4fbf448
check geometry possible types
AlvaroVega 3347387
add PolyLine impl
AlvaroVega 8485742
add test
AlvaroVega a055e3d
update feature test about poly
AlvaroVega 45717a2
add junit imports
AlvaroVega 7e31f6d
update PolyLine
AlvaroVega 006af08
Merge branch 'master' into task/add_polyline_arcgis
AlvaroVega 78917e8
update CNR
AlvaroVega 828d939
add fixme
AlvaroVega File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,3 +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) |
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
202 changes: 202 additions & 0 deletions
202
cygnus-common/src/main/java/com/telefonica/iot/cygnus/backends/arcgis/model/PolyLine.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,202 @@ | ||
/** | ||
* 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 PolyLine implements Geometry { | ||
private static final CygnusLogger LOGGER = new CygnusLogger(PolyLine.class); | ||
|
||
private static final String SPATIAL_REFERENCE_TAG = "spatialReference"; | ||
private static final String WKID_TAG = "wkid"; | ||
private static final String PATHS_TAG = "paths"; | ||
|
||
public List<List<double[]>> paths; | ||
|
||
private SpatialReference spatialReference; | ||
private int type = Geometry.TYPE_SHAPE; // TBD | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param paths | ||
* @param spatialReference | ||
*/ | ||
public PolyLine(List<List<double[]>> paths, SpatialReference spatialReference) { | ||
this.paths = paths; | ||
this.spatialReference = spatialReference; | ||
} | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param lat | ||
* @param lng | ||
*/ | ||
public PolyLine(List<List<double[]>> paths) { | ||
this(paths, SpatialReference.WGS84); | ||
} | ||
|
||
/** | ||
* SetValue. | ||
*/ | ||
public void setValue(Geometry g) throws ArcgisException { | ||
if (g.getGeometryType() == Geometry.TYPE_SHAPE) { | ||
PolyLine polyline = (PolyLine) g; | ||
this.paths = polyline.paths; | ||
} else { | ||
throw new ArcgisException("Invalid Geometry Type, Point expected."); | ||
} | ||
} | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param strPoint | ||
* @throws ArcgisException | ||
*/ | ||
public PolyLine(String strPolyline) throws ArcgisException { | ||
try { | ||
JsonObject jsonObject = JsonParser.parseString(strPolyline).getAsJsonObject(); | ||
String thePathsStr = jsonObject.get("paths").toString(); | ||
Gson gson = new Gson(); | ||
Type listType = new TypeToken<List<List<double[]>>>() {}.getType(); | ||
this.paths = gson.fromJson(thePathsStr, listType); | ||
this.spatialReference = SpatialReference.WGS84; | ||
} catch (NumberFormatException e) { | ||
LOGGER.error(e.getClass().getSimpleName() + " " + e.getMessage()); | ||
throw new ArcgisException("Unexpected string format for type PolyLine."); | ||
} | ||
} | ||
|
||
/** | ||
* 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(PATHS_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 PolyLine(json.get(PATHS_TAG).getAsString()); | ||
} catch (Exception e) { | ||
LOGGER.error(e.getClass().getSimpleName() + " " + e.getMessage()); | ||
throw new ArcgisException("Unable to parse PolyLine from json " + e.getMessage()); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* @return String | ||
*/ | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("{ \"paths\": ["); | ||
for (int i = 0; i < this.paths.size(); i++) { | ||
List<double[]> innerList = this.paths.get(i); | ||
for (int j = 0; j < innerList.size(); j++) { | ||
sb.append(" ["); | ||
sb.append("["); | ||
double[] array = innerList.get(j); | ||
for (double value : array) { | ||
sb.append(" ").append(value).append(","); | ||
} | ||
sb.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<List<double[]>> getPaths() { | ||
return this.paths; | ||
} | ||
|
||
@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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This leftover should be removed? Or is a kind of placeholder for future extensibility? In the second case, I'd suggest to add a
FIXME
comment telling so.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 828d939