Skip to content

Commit d3c8fa6

Browse files
committed
Upgrade JTS to 1.16.1 and add hilbert and morton curve commands
1 parent 149dd1d commit d3c8fa6

File tree

10 files changed

+403
-3
lines changed

10 files changed

+403
-3
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<dependency>
1111
<groupId>org.locationtech.jts</groupId>
1212
<artifactId>jts-core</artifactId>
13-
<version>1.16.0</version>
13+
<version>1.16.1</version>
1414
</dependency>
1515
<dependency>
1616
<groupId>org.osgeo</groupId>

src/config/config_geom.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,5 +1816,41 @@
18161816
"allPublicMethods": true,
18171817
"allPublicFields": true,
18181818
"allDeclaredFields": true
1819+
},
1820+
{
1821+
"name": "org.geometrycommands.HilbertCurveCommand",
1822+
"allDeclaredConstructors": true,
1823+
"allPublicConstructors": true,
1824+
"allDeclaredMethods": true,
1825+
"allPublicMethods": true,
1826+
"allPublicFields": true,
1827+
"allDeclaredFields": true
1828+
},
1829+
{
1830+
"name": "org.geometrycommands.HilbertCurveCommand$HilbertCurveOptions",
1831+
"allDeclaredConstructors": true,
1832+
"allPublicConstructors": true,
1833+
"allDeclaredMethods": true,
1834+
"allPublicMethods": true,
1835+
"allPublicFields": true,
1836+
"allDeclaredFields": true
1837+
},
1838+
{
1839+
"name": "org.geometrycommands.MortonCurveCommand",
1840+
"allDeclaredConstructors": true,
1841+
"allPublicConstructors": true,
1842+
"allDeclaredMethods": true,
1843+
"allPublicMethods": true,
1844+
"allPublicFields": true,
1845+
"allDeclaredFields": true
1846+
},
1847+
{
1848+
"name": "org.geometrycommands.MortonCurveCommand$MortonCurveOptions",
1849+
"allDeclaredConstructors": true,
1850+
"allPublicConstructors": true,
1851+
"allDeclaredMethods": true,
1852+
"allPublicMethods": true,
1853+
"allPublicFields": true,
1854+
"allDeclaredFields": true
18191855
}
18201856
]
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package org.geometrycommands;
2+
3+
import org.geometrycommands.HilbertCurveCommand.HilbertCurveOptions;
4+
import org.kohsuke.args4j.Option;
5+
import org.locationtech.jts.geom.Geometry;
6+
import org.locationtech.jts.geom.GeometryFactory;
7+
import org.locationtech.jts.shape.fractal.HilbertCurveBuilder;
8+
9+
import java.io.Reader;
10+
import java.io.Writer;
11+
12+
/**
13+
* A Command to create a Hilbert Curve Geometry.
14+
* @author Jared Erickson
15+
*/
16+
public class HilbertCurveCommand extends GeometryCommand<HilbertCurveOptions> {
17+
18+
/**
19+
* Get the command's name
20+
* @return The command's name
21+
*/
22+
@Override
23+
public String getName() {
24+
return "hilbertcurve";
25+
}
26+
27+
/**
28+
* Get the description of what the Command does
29+
* @return The description of what the Command does
30+
*/
31+
@Override
32+
public String getDescription() {
33+
return "Create a hilbert curve.";
34+
}
35+
36+
/**
37+
* Get the new HilbertCurveOptions
38+
* @return The new HilbertCurveOptions
39+
*/
40+
@Override
41+
public HilbertCurveOptions getOptions() {
42+
return new HilbertCurveOptions();
43+
}
44+
45+
/**
46+
* Create a Hilber Curve as a Geometry.
47+
* @param geometry The input Geometry
48+
* @param options The HilbertCurveOptions
49+
* @param reader The java.io.Reader
50+
* @param writer The java.io.Writer
51+
* @throws Exception if an error occurs
52+
*/
53+
@Override
54+
protected void processGeometry(Geometry geometry, HilbertCurveOptions options, Reader reader, Writer writer) throws Exception {
55+
HilbertCurveBuilder builder = new HilbertCurveBuilder(new GeometryFactory());
56+
builder.setExtent(geometry.getEnvelopeInternal());
57+
builder.setNumPoints(options.getNumberOfPoints());
58+
Geometry outputGeometry = builder.getGeometry();
59+
writer.write(writeGeometry(outputGeometry, options));
60+
}
61+
62+
/**
63+
* The HilbertCurveOptions
64+
*/
65+
public static class HilbertCurveOptions extends GeometryOptions {
66+
67+
/**
68+
* The number of points.
69+
*/
70+
@Option(name = "-n", aliases = "--number", usage = "The number of points.", required = true)
71+
private int numberOfPoints;
72+
73+
/**
74+
* Get the number of points.
75+
* @return The number of points.
76+
*/
77+
public int getNumberOfPoints() {
78+
return numberOfPoints;
79+
}
80+
81+
/**
82+
* Set the number of points.
83+
* @param numberOfPoints The number of points.
84+
*/
85+
public void setNumberOfPoints(int numberOfPoints) {
86+
this.numberOfPoints = numberOfPoints;
87+
}
88+
}
89+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package org.geometrycommands;
2+
3+
import org.geometrycommands.MortonCurveCommand.MortonCurveOptions;
4+
import org.kohsuke.args4j.Option;
5+
import org.locationtech.jts.geom.Geometry;
6+
import org.locationtech.jts.geom.GeometryFactory;
7+
import org.locationtech.jts.shape.fractal.MortonCurveBuilder;
8+
9+
import java.io.Reader;
10+
import java.io.Writer;
11+
12+
/**
13+
* A Command to create a Morton Curve Geometry.
14+
* @author Jared Erickson
15+
*/
16+
public class MortonCurveCommand extends GeometryCommand<MortonCurveOptions> {
17+
18+
/**
19+
* Get the command's name
20+
* @return The command's name
21+
*/
22+
@Override
23+
public String getName() {
24+
return "mortoncurve";
25+
}
26+
27+
/**
28+
* Get the description of what the Command does
29+
* @return The description of what the Command does
30+
*/
31+
@Override
32+
public String getDescription() {
33+
return "Create a morton curve.";
34+
}
35+
36+
/**
37+
* Get the new MortonCurveOptions
38+
* @return The new MortonCurveOptions
39+
*/
40+
@Override
41+
public MortonCurveOptions getOptions() {
42+
return new MortonCurveOptions();
43+
}
44+
45+
/**
46+
* Create a Morton Curve as a Geometry.
47+
* @param geometry The input Geometry
48+
* @param options The MortonCurveOptions
49+
* @param reader The java.io.Reader
50+
* @param writer The java.io.Writer
51+
* @throws Exception if an error occurs
52+
*/
53+
@Override
54+
protected void processGeometry(Geometry geometry, MortonCurveOptions options, Reader reader, Writer writer) throws Exception {
55+
MortonCurveBuilder builder = new MortonCurveBuilder(new GeometryFactory());
56+
builder.setExtent(geometry.getEnvelopeInternal());
57+
builder.setNumPoints(options.getNumberOfPoints());
58+
Geometry outputGeometry = builder.getGeometry();
59+
writer.write(writeGeometry(outputGeometry, options));
60+
}
61+
62+
/**
63+
* The MortonCurveOptions
64+
*/
65+
public static class MortonCurveOptions extends GeometryOptions {
66+
67+
/**
68+
* The number of points.
69+
*/
70+
@Option(name = "-n", aliases = "--number", usage = "The number of points.", required = true)
71+
private int numberOfPoints;
72+
73+
/**
74+
* Get the number of points.
75+
* @return The number of points.
76+
*/
77+
public int getNumberOfPoints() {
78+
return numberOfPoints;
79+
}
80+
81+
/**
82+
* Set the number of points.
83+
* @param numberOfPoints The number of points.
84+
*/
85+
public void setNumberOfPoints(int numberOfPoints) {
86+
this.numberOfPoints = numberOfPoints;
87+
}
88+
}
89+
}

src/main/resources/META-INF/services/org.geometrycommands.Command

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,6 @@ org.geometrycommands.UnionCommand
9797
org.geometrycommands.VoronoiDiagramCommand
9898
org.geometrycommands.WithinCommand
9999
org.geometrycommands.VersionCommand
100-
org.geometrycommands.HelpCommand
100+
org.geometrycommands.HelpCommand
101+
org.geometrycommands.HilbertCurveCommand
102+
org.geometrycommands.MortonCurveCommand

src/man/geom-hilbertcurve.1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.TH "geom-hilbertcurve" "1" "4 May 2012" "version 0.1"
2+
.SH NAME
3+
geom hilbertcurve
4+
.SH DESCRIPTION
5+
Create a hilbert curve.
6+
.SH USAGE
7+
geom hilbertcurve -g "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))" -n 18
8+
.SH OPTIONS
9+
-n --number: The number of points.
10+
.PP
11+
-g --geometry: The input geometry
12+
.PP
13+
--help : Print help message
14+
.PP
15+
--web-help : Open help in a web browser
16+
.PP

src/man/geom-mortoncurve.1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.TH "geom-mortoncurve" "1" "4 May 2012" "version 0.1"
2+
.SH NAME
3+
geom mortoncurve
4+
.SH DESCRIPTION
5+
Create a morton curve.
6+
.SH USAGE
7+
geom mortoncurve -g "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))" -n 54
8+
.SH OPTIONS
9+
-n --number: The number of points.
10+
.PP
11+
-g --geometry: The input geometry
12+
.PP
13+
--help : Print help message
14+
.PP
15+
--web-help : Open help in a web browser
16+
.PP

src/shell/geom_bash_comp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ _geom()
55
local line=${COMP_LINE}
66
COMPREPLY=()
77
if [[ "$line" == *"geom " ]]; then
8-
COMPREPLY=($(compgen -W 'angle arc arcpoly area asciiart boundary buffer centroid closelinestring combine contains convexHull coordinates count countpoints coveredby covers crosses delaunay densify difference dimension disjoint distance distanceline draw drawbase64 dump ellipse endpoint envelope equals fromwkb get grid hausdorffdistance help interiorpoint interpolatepoint intersection intersects isccw isclosed isempty isrectangle isring issimple isvalid iswithindistance kochsnowflake linedissolve linemerge list locatepoint mincircle minclearance mindiameter minrect narrow nearestpoints node normalize octagonalenvelope overlaps placepoint pointatangle polygonize project random randomwalk rectangle reduceprecision reflect relate reverse rotate scale shear sierpinskicarpet similarity simplify sinestar slice snap split spoke squircle startpoint subline supercircle symdifference text touches towkb translate type union version voronoi within' -- $cur))
8+
COMPREPLY=($(compgen -W 'angle arc arcpoly area asciiart boundary buffer centroid closelinestring combine contains convexHull coordinates count countpoints coveredby covers crosses delaunay densify difference dimension disjoint distance distanceline draw drawbase64 dump ellipse endpoint envelope equals fromwkb get grid hausdorffdistance help hilbertcurve interiorpoint interpolatepoint intersection intersects isccw isclosed isempty isrectangle isring issimple isvalid iswithindistance kochsnowflake linedissolve linemerge list locatepoint mincircle minclearance mindiameter minrect mortoncurve narrow nearestpoints node normalize octagonalenvelope overlaps placepoint pointatangle polygonize project random randomwalk rectangle reduceprecision reflect relate reverse rotate scale shear sierpinskicarpet similarity simplify sinestar slice snap split spoke squircle startpoint subline supercircle symdifference text touches towkb translate type union version voronoi within' -- $cur))
99
elif [[ "$line" == *"geom angle "* ]]; then
1010
COMPREPLY=($(compgen -W '--help --web-help -g --geometry -o --otherGeometry -t --type' -- $cur))
1111
elif [[ "$line" == *"geom arc "* ]]; then
@@ -80,6 +80,8 @@ _geom()
8080
COMPREPLY=($(compgen -W '--help --web-help -g --geometry -o --otherGeometry' -- $cur))
8181
elif [[ "$line" == *"geom help "* ]]; then
8282
COMPREPLY=($(compgen -W '--help --web-help' -- $cur))
83+
elif [[ "$line" == *"geom hilbertcurve "* ]]; then
84+
COMPREPLY=($(compgen -W '--help --web-help -g --geometry -n --number' -- $cur))
8385
elif [[ "$line" == *"geom interiorpoint "* ]]; then
8486
COMPREPLY=($(compgen -W '--help --web-help -g --geometry' -- $cur))
8587
elif [[ "$line" == *"geom interpolatepoint "* ]]; then
@@ -122,6 +124,8 @@ _geom()
122124
COMPREPLY=($(compgen -W '--help --web-help -g --geometry' -- $cur))
123125
elif [[ "$line" == *"geom minrect "* ]]; then
124126
COMPREPLY=($(compgen -W '--help --web-help -g --geometry' -- $cur))
127+
elif [[ "$line" == *"geom mortoncurve "* ]]; then
128+
COMPREPLY=($(compgen -W '--help --web-help -g --geometry -n --number' -- $cur))
125129
elif [[ "$line" == *"geom narrow "* ]]; then
126130
COMPREPLY=($(compgen -W '--help --web-help -g --geometry' -- $cur))
127131
elif [[ "$line" == *"geom nearestpoints "* ]]; then
@@ -319,6 +323,9 @@ _geom()
319323
if [[ "help" == "$nm"* ]]; then
320324
COMPREPLY=("${COMPREPLY[@]}" $(compgen -W 'help'))
321325
fi
326+
if [[ "hilbertcurve" == "$nm"* ]]; then
327+
COMPREPLY=("${COMPREPLY[@]}" $(compgen -W 'hilbertcurve'))
328+
fi
322329
if [[ "interiorpoint" == "$nm"* ]]; then
323330
COMPREPLY=("${COMPREPLY[@]}" $(compgen -W 'interiorpoint'))
324331
fi
@@ -382,6 +389,9 @@ _geom()
382389
if [[ "minrect" == "$nm"* ]]; then
383390
COMPREPLY=("${COMPREPLY[@]}" $(compgen -W 'minrect'))
384391
fi
392+
if [[ "mortoncurve" == "$nm"* ]]; then
393+
COMPREPLY=("${COMPREPLY[@]}" $(compgen -W 'mortoncurve'))
394+
fi
385395
if [[ "narrow" == "$nm"* ]]; then
386396
COMPREPLY=("${COMPREPLY[@]}" $(compgen -W 'narrow'))
387397
fi
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package org.geometrycommands;
2+
3+
import org.geometrycommands.HilbertCurveCommand.HilbertCurveOptions;
4+
import org.junit.Test;
5+
6+
import java.io.Reader;
7+
import java.io.StringReader;
8+
import java.io.StringWriter;
9+
10+
import static org.junit.Assert.assertEquals;
11+
12+
/**
13+
* The HilbertCurveCommand UnitTest
14+
* @author Jared Erickson
15+
*/
16+
public class HilbertCurveCommandTest extends BaseTest {
17+
18+
private final String inputGeometry = "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))";
19+
20+
private final String resultGeometry = "LINESTRING (0 0, 0 1.4285714285714286, 1.4285714285714286 1.4285714285714286, " +
21+
"1.4285714285714286 0, 2.857142857142857 0, 4.285714285714286 0, 4.285714285714286 1.4285714285714286, " +
22+
"2.857142857142857 1.4285714285714286, 2.857142857142857 2.857142857142857, 4.285714285714286 2.857142857142857, " +
23+
"4.285714285714286 4.285714285714286, 2.857142857142857 4.285714285714286, 1.4285714285714286 4.285714285714286, " +
24+
"1.4285714285714286 2.857142857142857, 0 2.857142857142857, 0 4.285714285714286, 0 5.714285714285714, " +
25+
"1.4285714285714286 5.714285714285714, 1.4285714285714286 7.142857142857143, 0 7.142857142857143, " +
26+
"0 8.571428571428571, 0 10, 1.4285714285714286 10, 1.4285714285714286 8.571428571428571, " +
27+
"2.857142857142857 8.571428571428571, 2.857142857142857 10, 4.285714285714286 10, 4.285714285714286 8.571428571428571, " +
28+
"4.285714285714286 7.142857142857143, 2.857142857142857 7.142857142857143, 2.857142857142857 5.714285714285714, " +
29+
"4.285714285714286 5.714285714285714, 5.714285714285714 5.714285714285714, 7.142857142857143 5.714285714285714, " +
30+
"7.142857142857143 7.142857142857143, 5.714285714285714 7.142857142857143, 5.714285714285714 8.571428571428571, " +
31+
"5.714285714285714 10, 7.142857142857143 10, 7.142857142857143 8.571428571428571, 8.571428571428571 8.571428571428571, " +
32+
"8.571428571428571 10, 10 10, 10 8.571428571428571, 10 7.142857142857143, 8.571428571428571 7.142857142857143, " +
33+
"8.571428571428571 5.714285714285714, 10 5.714285714285714, 10 4.285714285714286, 10 2.857142857142857, " +
34+
"8.571428571428571 2.857142857142857, 8.571428571428571 4.285714285714286, 7.142857142857143 4.285714285714286, " +
35+
"5.714285714285714 4.285714285714286, 5.714285714285714 2.857142857142857, 7.142857142857143 2.857142857142857, " +
36+
"7.142857142857143 1.4285714285714286, 5.714285714285714 1.4285714285714286, 5.714285714285714 0, 7.142857142857143 0, " +
37+
"8.571428571428571 0, 8.571428571428571 1.4285714285714286, 10 1.4285714285714286, 10 0)";
38+
39+
@Test
40+
public void execute() throws Exception {
41+
42+
HilbertCurveOptions options = new HilbertCurveOptions();
43+
options.setGeometry(inputGeometry);
44+
options.setNumberOfPoints(30);
45+
46+
Reader reader = new StringReader(inputGeometry);
47+
StringWriter writer = new StringWriter();
48+
49+
HilbertCurveCommand command = new HilbertCurveCommand();
50+
command.execute(options, reader, writer);
51+
assertEquals(resultGeometry, writer.getBuffer().toString());
52+
}
53+
54+
@Test
55+
public void run() throws Exception {
56+
// Geometry from options
57+
String result = runApp(new String[]{
58+
"hilbertcurve",
59+
"-g", inputGeometry,
60+
"-n", "30"
61+
}, null);
62+
assertEquals(resultGeometry, result);
63+
64+
// Geometry from input stream
65+
result = runApp(new String[]{
66+
"hilbertcurve",
67+
"-n", "30"
68+
}, inputGeometry);
69+
assertEquals(resultGeometry, result);
70+
}
71+
}

0 commit comments

Comments
 (0)