Geometry Commands
-
Upload
jared-erickson -
Category
Technology
-
view
403 -
download
1
description
Transcript of Geometry Commands
geometry commandsJared Erickson
CUGOS
June 20th 2012
What is it?Command line application for
geometry
Buffer a pointecho "POINT (1 1)" | geom buffer -d 100
Reproject a Pointecho "POINT (1 1)" | geom project -s "EPSG:4326" -t "EPSG:2927"
Generate random pointsecho "POINT (1 1)" | geom buffer -d 100 | geom random -n 200
"Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams,
because that is a universal interface."
Write programs that do one thing and do it well...
buffer centroid envelope convexHull voronoiDiagram
Write programs to work together... Unix Pipes
stdin -> program -> stdout
... program -> stdout -> stdin -> program ...
buffer | centroid | envelopewkt -> buffer -> wkt | wkt -> centroid -> wkt | wkt -> envelope -> envelope
Write programs to handle text streams...
WKTPOINT (1 1)
LINESTRING (0 0, 5 5, 10 10)POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))
Geometry Commands
• Java command line application
• JTS - Geometry
• Proj4j - Projections
• Args4j - Command line parsing
• https://github.com/jericks/geometrycommands
Commandsgeom list
list arc arcpoly area boundary buffer centroid combinecontains convexHull coordinates count countpoints coveredby
covers crosses delaunay densify drawdump ellipse difference hausdorffdistance disjoint distance distanceline envelope equals interiorpoint interpolatepoint
intersection intersects isclosed isempty isrectangle isring issimple isvalid iswithindistance kochsnowflake linemerge locatepoint type grid endpoint get startpoint mincircle minclearance mindiameter minrect node normalize octagonalenvelope overlaps placepoint pointatangle
polygonize project random randomwalk rectanglereflect relate reverse rotate scale shear sierpinskicarpet similarity
simplify sinestar snap squircle subline supercircle symdifference text touches translate union voronoi within
Processecho "POINT (10 10)" | geom buffer -d 5
POLYGON ((15 10, 14.903926402016152 9.024548389919358, 14.619397662556434 8.08658283817455, 14.157348061512726 7.222148834901989, 13.535533905932738 6.464466094067262, 12.777851165098012 5.842651938487274, 11.91341716182545
5.380602337443566, 10.975451610080642 5.096073597983848, 10 5, 9.024548389919358 5.096073597983848, 8.086582838174552 5.380602337443566, 7.22214883490199 5.842651938487274, 6.464466094067262 6.464466094067262, 5.842651938487274
7.222148834901989, 5.380602337443566 8.086582838174554, 5.096073597983847 9.024548389919362, 5 10.000000000000004, 5.096073597983849 10.975451610080647, 5.380602337443569 11.913417161825455, 5.842651938487277 12.777851165098017, 6.4644660940672685 13.535533905932743, 7.222148834901996 14.157348061512732, 8.08658283817456 14.619397662556437,
9.024548389919369 14.903926402016154, 10.000000000000012 15, 10.975451610080654 14.90392640201615, 11.913417161825462 14.619397662556429, 12.777851165098024 14.157348061512717, 13.535533905932748 13.535533905932725, 14.157348061512735 12.777851165097996, 14.619397662556441 11.913417161825432,
14.903926402016156 10.975451610080622, 15 10))
Compareecho "POINT (10 10)" | geom buffer -d 5 | geom
contains -o "POINT (5 5)"
false
Reprojectecho "POINT (1 1)" | geom project -s "EPSG:4326" -t
"EPSG:2927"
POINT (39722967.09614658 19129704.97907105)
Drawecho "POINT (10 10)" | geom buffer -d 5 | geom draw
&& open image.png
Call command per linecat > points.wkt
POINT (1 1)POINT (2 2)
cat points.wkt | while read line; do geom buffer -d 10 -g "$line"; done;
POLYGON ((11 1, 10.807852804032304 -0.9509032201612824, … , 10.807852804032311 2.9509032201612437, 11 1))POLYGON ((12 2, 11.807852804032304 0.0490967798387176, … , 12 2))
cat points.wkt | while read -r line; do geom buffer -d 10 -g "$line"; done
POLYGON ((11 1, 10.807852804032304 -0.9509032201612824, … , 11 1))POLYGON ((12 2, 11.807852804032304 0.0490967798387176, … , 12 2))
Combinecat points.wkt | while read -r line; do geom buffer -d 10 -g
"$line"; done | geom combineMULTIPOLYGON (((11 1, 10.807852804032304 -0.9509032201612824, 10.238795325112868 -2.826834323650898, 9.314696123025453
-4.555702330196022, 8.071067811865476 -6.071067811865475, 6.555702330196023 -7.314696123025453, 4.826834323650898 -8.238795325112868, 2.9509032201612833 -8.807852804032304, 1.0000000000000007 -9, -0.9509032201612819 -8.807852804032304,
-2.826834323650897 -8.238795325112868, -4.55570233019602 -7.314696123025453, -6.071067811865475 -6.0710678118654755, -7.314696123025453 -4.555702330196022, -8.238795325112868 -2.8268343236508944, -8.807852804032306 -0.9509032201612773, -9
1.0000000000000075, -8.807852804032303 2.950903220161292, -8.238795325112862 4.826834323650909, -7.3146961230254455 6.555702330196034, -6.071067811865463 8.071067811865486, -4.555702330196008 9.314696123025463, -2.826834323650879
10.238795325112875, -0.9509032201612606 10.807852804032308, 1.0000000000000249 11, 2.950903220161309 10.807852804032299, 4.826834323650925 10.238795325112857, 6.555702330196048 9.314696123025435, 8.071067811865499 8.07106781186545,
9.314696123025472 6.555702330195993, 10.238795325112882 4.826834323650862, 10.807852804032311 2.9509032201612437, 11 1)), ((12 2, 11.807852804032304 0.0490967798387176, 11.238795325112868 -1.826834323650898, 10.314696123025453
-3.5557023301960218, 9.071067811865476 -5.071067811865475, 7.555702330196023 -6.314696123025453, 5.826834323650898 -7.238795325112868, 3.9509032201612833 -7.807852804032304, 2.0000000000000004 -8, 0.0490967798387181 -7.807852804032304,
-1.826834323650897 -7.238795325112868, -3.55570233019602 -6.314696123025453, -5.071067811865475 -5.0710678118654755, -6.314696123025453 -3.5557023301960218, -7.238795325112868 -1.8268343236508944, -7.807852804032306 0.0490967798387227, -8
2.0000000000000075, -7.8078528040323025 3.950903220161292, -7.2387953251128625 5.826834323650909, -6.3146961230254455 7.555702330196034, -5.071067811865463 9.071067811865486, -3.5557023301960076 10.314696123025463, -1.8268343236508788
11.238795325112875, 0.0490967798387394 11.807852804032308, 2.000000000000025 12, 3.950903220161309 11.807852804032299, 5.826834323650925 11.238795325112857, 7.555702330196048 10.314696123025435, 9.071067811865499 9.07106781186545,
10.314696123025472 7.555702330195993, 11.238795325112882 5.826834323650862, 11.807852804032311 3.9509032201612437, 12 2)))
Dumpecho "POINT (1 1)" | geom buffer -d 100 | geom random -
n 100 | geom dump > random.wkt
POINT (23.161455744394658 -77.95246871808072)POINT (58.930083365685135 -61.904759742385096)POINT (-68.59023262463613 -54.78626222287515)POINT (-82.5800340659446 -28.375102984177744)POINT (62.05862576956568 45.25807594023459)POINT (74.43518384825472 -10.092639433362095)…
Draw multiple geometriesecho "POINT (10 10)" > geoms.wkt
cat geoms.wkt | geom buffer -d 10 >> geoms.wktcat geoms.wkt | geom combine | geom draw && open
image.png
Draw multiple geometriesecho "POINT (100 100)" > geoms.wkt
cat geoms.wkt | geom get -n 0 | geom buffer -d 10 >> geoms.wkt cat geoms.wkt | geom get -n 0 | geom buffer -d 20 >> geoms.wkt cat geoms.wkt | geom get -n 0 | geom buffer -d 30 >> geoms.wkt cat geoms.wkt | geom combine | geom draw && open image.png
Point at Angleecho "POINT (10 10)" > center.wkt
cat center.wkt | geom pointatangle -a 0 -d 10 >> center.wkt cat center.wkt | geom get -n 0 | geom pointatangle -a 45 -d 5 >> center.wkt cat center.wkt | geom get -n 0 | geom pointatangle -a 90 -d 10 >> center.wkt cat center.wkt | geom get -n 0 | geom pointatangle -a 135 -d 5 >> center.wkt cat center.wkt | geom get -n 0 | geom pointatangle -a 180 -d 10 >> center.wkt cat center.wkt | geom get -n 0 | geom pointatangle -a 225 -d 5 >> center.wkt cat center.wkt | geom get -n 0 | geom pointatangle -a 270 -d 10 >> center.wkt cat center.wkt | geom get -n 0 | geom pointatangle -a 315 -d 5 >> center.wkt
cat center.wkt | geom combine | geom draw && open image.png
Backticsecho "POINT (10 10)" > point.wkt
echo "POINT (0 0)" | geom buffer -d 10 | geom contains -o "`cat point.wkt | geom get -n 0`"
false
Generate Random Pointsecho "POINT (1 1)" | geom buffer -d 100 | geom
random -n 20
MULTIPOINT ((28.654023089302072 -44.01821817278271), (81.83017489687163 -23.86819073039706), (2.105166479839937 36.12893454538721), (4.227942694802536 -75.42526935983172), (70.36226203781283 55.09734125747187), (-24.57828687972821
40.21049354265716), (43.29398472591029 91.04707992971149), (-10.753927532104086 29.320031764200024), (-81.14902146405959 8.312362640063384), (29.670956290372317 1.1014786268571584), (42.092039630473465 83.01841893953664), (-3.8268655554251154 -33.81236693090035), (-54.61643432275327 -69.03248995687024), (18.216453654179105 -46.68047579703787), (69.16611402164975 31.101723885056686), (-43.36423562242582 -76.70347656510657), (84.68024160811188 -46.630576818012635), (-52.67048441979452 -65.85207992789142),
(-82.00381658701411 -14.714381798142469), (72.18321150088343 -60.363316389278076))
Random Walkecho "POINT (100 100)" | geom randomwalk -n 100 -a 45
-d 10 | geom draw -c && open image.png
Koch Snowflake
echo "POINT (1 1)" | geom envelope -e 100 | geom kochsnowflake -n 1000 | geom draw && open image.png
Sierpinski Carpetecho "POINT (1 1)" | geom envelope -e 100 | geom
sierpinskicarpet -n 1000 | geom draw && open image.png
Text
geom text -t "Hi" | geom draw -c && open image.png
Sine Starecho "POINT (100 100)" | geom sinestar -l 0.9 -n 12 -p 1000 -w 500 -h 500 | geom draw && open image.png
Rectangleecho "POINT (100 100)" | geom rectangle -p 30 -w 500 -h
500 | geom draw -c && open image.png
Ellipseecho "POINT (100 100)" | geom ellipse -p 30 -w 500 -h
500 | geom draw -c && open image.png
Squircleecho "POINT (100 100)" | geom squircle -p 30 -w 500 -h
500 | geom draw -c && open image.png
Supercircleecho "POINT (100 100)" | geom supercircle -o 3 -p 100 -
w 500 -h 500 | geom draw -c && open image.png
Arcecho "POINT (100 100)" | geom arc -a 45 -e 90 -d -p 20 -
w 500 -h 500 | geom draw -c && open image.png
Arc polygonecho "POINT (100 100)" | geom arcpoly -a 45 -e 90 -d -p
20 -w 500 -h 500 | geom draw -c && open image.png
PostgreSQLpsql -U postgres -d postgres -c "select St_asText
(the_geom) from washington_2927 where fid=5" -t | geom draw && open image.png
PostgreSQLpsql -U postgres -d postgres -c "select St_asText
(st_collect(the_geom)) from washington_2927" -t | geom draw && open image.png
PostgreSQLpsql -U postgres -d postgres -c "select St_asText
(the_geom) from washington_2927" -t | geom combine | geom draw && open image.png
GeoScript: convert to kmlecho "POINT (1 1)" | geom buffer -d 10 | geoscript-
groovy -e "println geoscript.geom.Geometry.fromWKT(System.in.text).kml"
<Polygon><outerBoundaryIs><LinearRing><coordinates>11.0,1.0 10.807852804032304,-0.9509032201612824 10.238795325112868,-2.826834323650898 9.314696123025453,-4.555702330196022 8.071067811865476,-6.071067811865475 6.555702330196023,-7.314696123025453 4.826834323650898,-8.238795325112868 2.9509032201612833,-8.807852804032304
1.0000000000000007,-9.0 -0.9509032201612819,-8.807852804032304 -2.826834323650897,-8.238795325112868 -4.55570233019602,-7.314696123025453 -6.071067811865475,-6.0710678118654755 -7.314696123025453,-4.555702330196022
-8.238795325112868,-2.8268343236508944 -8.807852804032306,-0.9509032201612773 -9.0,1.0000000000000075 -8.807852804032303,2.950903220161292 -8.238795325112862,4.826834323650909 -7.3146961230254455,6.555702330196034 -6.071067811865463,8.071067811865486 -4.555702330196008,9.314696123025463 -2.826834323650879,10.238795325112875
-0.9509032201612606,10.807852804032308 1.0000000000000249,11.0 2.950903220161309,10.807852804032299 4.826834323650925,10.238795325112857 6.555702330196048,9.314696123025435 8.071067811865499,8.07106781186545
9.314696123025472,6.555702330195993 10.238795325112882,4.826834323650862 10.807852804032311,2.9509032201612437 11.0,1.0</coordinates></LinearRing></outerBoundaryIs></Polygon>
GeoScript: draw shapefilegeoscript-groovy -e "println new
geoscript.geom.GeometryCollection(new geoscript.layer.Shapefile('states.shp').features.collect
{it.geom}).wkt" | geom draw && open image.png
GeoScript: write shapefileecho "POINT (1 1)" | geom buffer -d 100 | geom random -
n 100 | geoscript-groovy -e "new geoscript.workspace.Directory('.').create(new
geoscript.feature.Schema('random', [['the_geom','Point','EPSG:4326']])).add(geoscript.geom.Geometry.fromWKT
(System.in.text).geometries.collect{new geoscript.feature.Feature(['the_geom': it],null)})"
Geocodingcurl "http://geocoder.us/service/csv/geocode?zip=95472" | awk -F ", " '{print "POINT ("$2 " " $1 ")"}' | geom buffer -d
10 | geom draw && open image.png
USGS Earthquakescurl http://earthquake.usgs.gov/earthquakes/catalogs/
eqs1day-M2.5.txt | awk -F ',' '{if (NR!=1) {print "POINT ("$8" "$7")"}}' | geom combine | geom draw && open
image.png
WMScurl -o map.jpg "http://vmap0.tiles.osgeo.org/wms/vmap0?LAYERS=basic&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&FORMAT=image%2Fjpeg&SRS=EPSG%3A4326&BBOX=-123.07,46.66,-121.14,47.48&WIDTH=500&HEIGHT=400"
echo "POINT (-122.429452 47.125627)" | geom buffer -d 0.2 | geom draw -w 500 -h 400 -e "-123.07,46.66,-121.14,47.48" -i map.jpg && open image.png
Install
• Install Java
• Download
• https://github.com/jericks/geometrycommands/downloads
• Put on path
• export PATH = /whereever/you/put/it/geom/bin
Help
• View commands
• geom list
• Get help on a command
• geom buffer --help
• Man pages
• man geom
• man geom-buffer
Web Site (Sphinx)
Extend• Create a Java class that implements Command
Interface
• or extends GeometryCommand
• or extends OtherGeometryCommand
• Add command line options by creating an Options subclass with Args4J annotations
• Java Service Provider Interface
• META-INF/services/org.geometrycommands/Command
• Add line with the full path (package and class name)
Thank you!