Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
VIPSCommon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VIPS
VIPSCommon
Commits
a7601109
Commit
a7601109
authored
1 year ago
by
Tor-Einar Skog
Browse files
Options
Downloads
Patches
Plain Diff
Add getGeoJSONFeatureFromGeometry
parent
f51a3605
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/no/nibio/vips/gis/GISUtil.java
+25
-5
25 additions, 5 deletions
src/main/java/no/nibio/vips/gis/GISUtil.java
with
25 additions
and
5 deletions
src/main/java/no/nibio/vips/gis/GISUtil.java
+
25
−
5
View file @
a7601109
...
...
@@ -42,7 +42,7 @@ import org.wololo.jts2geojson.GeoJSONWriter;
/**
* Handy tools for GIS operations
* @copyright 20
17
<a href="http://www.nibio.no/">NIBIO</a>
* @copyright 20
23
<a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public
class
GISUtil
{
...
...
@@ -142,7 +142,7 @@ public class GISUtil {
}
/**
* Convert one JTS Geometry object into a GeoJSON
feature
* Convert one JTS Geometry object into a
complete
GeoJSON
String
* @param geometry
* @param properties
* @return
...
...
@@ -154,14 +154,28 @@ public class GISUtil {
return
""
;
}
List
<
Feature
>
features
=
new
ArrayList
<>();
features
.
add
(
this
.
getGeoJSONFeatureFromGeometry
(
geometry
,
properties
));
GeoJSONWriter
writer
=
new
GeoJSONWriter
();
features
.
add
(
new
Feature
(
writer
.
write
(
geometry
),
properties
));
FeatureCollection
json
=
writer
.
write
(
features
);
return
json
.
toString
();
}
/**
* Convert one JTS Geometry object into a GeoJSON Feature
* @param geometry
* @param properties
* @return
*/
public
Feature
getGeoJSONFeatureFromGeometry
(
Geometry
geometry
,
Map
<
String
,
Object
>
properties
)
{
if
(
geometry
==
null
)
{
return
null
;
}
GeoJSONWriter
writer
=
new
GeoJSONWriter
();
return
new
Feature
(
writer
.
write
(
geometry
),
properties
);
}
/**
* If you have WGS84 coordinates, th
* @param coordinate in WGS84 system
...
...
@@ -172,6 +186,12 @@ public class GISUtil {
GeometryFactory
gf
=
new
GeometryFactory
(
new
PrecisionModel
(),
4326
);
return
gf
.
createPoint
(
coordinate
);
}
public
Point
createPointWGS84
(
Double
longitude
,
Double
latitude
)
{
Coordinate
coordinate
=
new
Coordinate
(
longitude
,
latitude
);
return
this
.
createPointWGS84
(
coordinate
);
}
/**
* Calculate distance between two points, courtesy of <a href="http://www.movable-type.co.uk/scripts/latlong.html">this page</a>. Explanation:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment