geometry commands
Jared Erickson
CUGOS
June 20th 2012
What is it?
Command line application for
geometry
Buffer a point
echo "POINT (1 1)" | geom buffer -d 100
Reproject a Point
echo "POINT (1 1)" | geom project -s "EPSG:4326" ...
"Write programs that do
one thing and do it well.
Write programs to work
together.Write programs
to handle text streams,
b...
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 ...
buf...
Write programs to handle
text streams...
WKT
POINT (1 1)
LINESTRING (0 0, 5 5, 10 10)
POLYGON ((0 0, 0 10, 10 10, 10 0, 0 ...
Geometry Commands
• Java command line application
• JTS - Geometry
• Proj4j - Projections
• Args4j - Command line parsing
...
Commands
geom list
list arc arcpoly area boundary buffer centroid combine
contains convexHull coordinates count countpoint...
Process
echo "POINT (10 10)" | geom buffer -d 5
POLYGON ((15 10, 14.903926402016152 9.024548389919358, 14.619397662556434 ...
Compare
echo "POINT (10 10)" | geom buffer -d 5 | geom
contains -o "POINT (5 5)"
false
Reproject
echo "POINT (1 1)" | geom project -s "EPSG:4326" -t
"EPSG:2927"
POINT (39722967.09614658 19129704.97907105)
Draw
echo "POINT (10 10)" | geom buffer -d 5 | geom draw
&& open image.png
Call command per line
cat > points.wkt
POINT (1 1)
POINT (2 2)
cat points.wkt | while read line; do geom buffer -d 10 -g
"...
Combine
cat points.wkt | while read -r line; do geom buffer -d 10 -g
"$line"; done | geom combine
MULTIPOLYGON (((11 1, 10...
Dump
echo "POINT (1 1)" | geom buffer -d 100 | geom random -
n 100 | geom dump > random.wkt
POINT (23.161455744394658 -77....
Draw multiple geometries
echo "POINT (10 10)" > geoms.wkt
cat geoms.wkt | geom buffer -d 10 >> geoms.wkt
cat geoms.wkt | g...
Draw multiple geometries
echo "POINT (100 100)" > geoms.wkt
cat geoms.wkt | geom get -n 0 | geom buffer -d 10 >> geoms.wkt...
Point at Angle
echo "POINT (10 10)" > center.wkt
cat center.wkt | geom pointatangle -a 0 -d 10 >> center.wkt
cat center.wk...
Backtics
echo "POINT (10 10)" > point.wkt
echo "POINT (0 0)" | geom buffer -d 10 | geom
contains -o "`cat point.wkt | geom...
Generate Random Points
echo "POINT (1 1)" | geom buffer -d 100 | geom
random -n 20
MULTIPOINT ((28.654023089302072 -44.018...
Random Walk
echo "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 Carpet
echo "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 Star
echo "POINT (100 100)" | geom sinestar -l 0.9 -n 12 -p
1000 -w 500 -h 500 | geom draw && open image.png
Rectangle
echo "POINT (100 100)" | geom rectangle -p 30 -w 500 -h
500 | geom draw -c && open image.png
Ellipse
echo "POINT (100 100)" | geom ellipse -p 30 -w 500 -h
500 | geom draw -c && open image.png
Squircle
echo "POINT (100 100)" | geom squircle -p 30 -w 500 -h
500 | geom draw -c && open image.png
Supercircle
echo "POINT (100 100)" | geom supercircle -o 3 -p 100 -
w 500 -h 500 | geom draw -c && open image.png
Arc
echo "POINT (100 100)" | geom arc -a 45 -e 90 -d -p 20 -
w 500 -h 500 | geom draw -c && open image.png
Arc polygon
echo "POINT (100 100)" | geom arcpoly -a 45 -e 90 -d -p
20 -w 500 -h 500 | geom draw -c && open image.png
PostgreSQL
psql -U postgres -d postgres -c "select St_asText
(the_geom) from washington_2927 where fid=5" -t |
geom draw &&...
PostgreSQL
psql -U postgres -d postgres -c "select St_asText
(st_collect(the_geom)) from washington_2927" -t | geom
draw &...
PostgreSQL
psql -U postgres -d postgres -c "select St_asText
(the_geom) from washington_2927" -t | geom combine |
geom dra...
GeoScript: convert to kml
echo "POINT (1 1)" | geom buffer -d 10 | geoscript-
groovy -e "println geoscript.geom.Geometry.f...
GeoScript: draw shapefile
geoscript-groovy -e "println new
geoscript.geom.GeometryCollection(new
geoscript.layer.Shapefile('...
GeoScript: write shapefile
echo "POINT (1 1)" | geom buffer -d 100 | geom random -
n 100 | geoscript-groovy -e "new
geoscri...
Geocoding
curl "http://geocoder.us/service/csv/geocode?zip=95472" |
awk -F ", " '{print "POINT ("$2 " " $1 ")"}' | geom bu...
USGS Earthquakes
curl http://earthquake.usgs.gov/earthquakes/catalogs/
eqs1day-M2.5.txt | awk -F ',' '{if (NR!=1) {print "...
WMS
curl -o map.jpg "http://vmap0.tiles.osgeo.org/wms/vmap0?
LAYERS=basic&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetM
ap&STYLES...
Install
• Install Java
• Download
• https://github.com/jericks/geometrycommands/
downloads
• Put on path
• export PATH = /...
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 OtherGeometryComm...
Thank you!
Geometry Commands
Upcoming SlideShare
Loading in …5
×

Geometry Commands

575 views
467 views

Published on

Geometry commands is a geometry command line application that follows the unix philosophy.

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
575
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Geometry Commands

  1. 1. geometry commands Jared Erickson CUGOS June 20th 2012
  2. 2. What is it? Command line application for geometry
  3. 3. Buffer a point echo "POINT (1 1)" | geom buffer -d 100 Reproject a Point echo "POINT (1 1)" | geom project -s "EPSG:4326" -t "EPSG:2927" Generate random points echo "POINT (1 1)" | geom buffer -d 100 | geom random -n 200
  4. 4. "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."
  5. 5. Write programs that do one thing and do it well... buffer centroid envelope convexHull voronoiDiagram
  6. 6. Write programs to work together... Unix Pipes stdin -> program -> stdout ... program -> stdout -> stdin -> program ... buffer | centroid | envelope wkt -> buffer -> wkt | wkt -> centroid -> wkt | wkt -> envelope -> envelope
  7. 7. Write programs to handle text streams... WKT POINT (1 1) LINESTRING (0 0, 5 5, 10 10) POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))
  8. 8. Geometry Commands • Java command line application • JTS - Geometry • Proj4j - Projections • Args4j - Command line parsing • https://github.com/jericks/geometrycommands
  9. 9. Commands geom list list arc arcpoly area boundary buffer centroid combine contains convexHull coordinates count countpoints coveredby covers crosses delaunay densify draw dump 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 rectangle reflect relate reverse rotate scale shear sierpinskicarpet similarity simplify sinestar snap squircle subline supercircle symdifference text touches translate union voronoi within
  10. 10. Process echo "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))
  11. 11. Compare echo "POINT (10 10)" | geom buffer -d 5 | geom contains -o "POINT (5 5)" false
  12. 12. Reproject echo "POINT (1 1)" | geom project -s "EPSG:4326" -t "EPSG:2927" POINT (39722967.09614658 19129704.97907105)
  13. 13. Draw echo "POINT (10 10)" | geom buffer -d 5 | geom draw && open image.png
  14. 14. Call command per line cat > 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))
  15. 15. Combine cat points.wkt | while read -r line; do geom buffer -d 10 -g "$line"; done | geom combine MULTIPOLYGON (((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)))
  16. 16. Dump echo "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) …
  17. 17. Draw multiple geometries echo "POINT (10 10)" > geoms.wkt cat geoms.wkt | geom buffer -d 10 >> geoms.wkt cat geoms.wkt | geom combine | geom draw && open image.png
  18. 18. Draw multiple geometries echo "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
  19. 19. Point at Angle echo "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
  20. 20. Backtics echo "POINT (10 10)" > point.wkt echo "POINT (0 0)" | geom buffer -d 10 | geom contains -o "`cat point.wkt | geom get -n 0`" false
  21. 21. Generate Random Points echo "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))
  22. 22. Random Walk echo "POINT (100 100)" | geom randomwalk -n 100 -a 45 -d 10 | geom draw -c && open image.png
  23. 23. Koch Snowflake echo "POINT (1 1)" | geom envelope -e 100 | geom kochsnowflake -n 1000 | geom draw && open image.png
  24. 24. Sierpinski Carpet echo "POINT (1 1)" | geom envelope -e 100 | geom sierpinskicarpet -n 1000 | geom draw && open image.png
  25. 25. Text geom text -t "Hi" | geom draw -c && open image.png
  26. 26. Sine Star echo "POINT (100 100)" | geom sinestar -l 0.9 -n 12 -p 1000 -w 500 -h 500 | geom draw && open image.png
  27. 27. Rectangle echo "POINT (100 100)" | geom rectangle -p 30 -w 500 -h 500 | geom draw -c && open image.png
  28. 28. Ellipse echo "POINT (100 100)" | geom ellipse -p 30 -w 500 -h 500 | geom draw -c && open image.png
  29. 29. Squircle echo "POINT (100 100)" | geom squircle -p 30 -w 500 -h 500 | geom draw -c && open image.png
  30. 30. Supercircle echo "POINT (100 100)" | geom supercircle -o 3 -p 100 - w 500 -h 500 | geom draw -c && open image.png
  31. 31. Arc echo "POINT (100 100)" | geom arc -a 45 -e 90 -d -p 20 - w 500 -h 500 | geom draw -c && open image.png
  32. 32. Arc polygon echo "POINT (100 100)" | geom arcpoly -a 45 -e 90 -d -p 20 -w 500 -h 500 | geom draw -c && open image.png
  33. 33. PostgreSQL psql -U postgres -d postgres -c "select St_asText (the_geom) from washington_2927 where fid=5" -t | geom draw && open image.png
  34. 34. PostgreSQL psql -U postgres -d postgres -c "select St_asText (st_collect(the_geom)) from washington_2927" -t | geom draw && open image.png
  35. 35. PostgreSQL psql -U postgres -d postgres -c "select St_asText (the_geom) from washington_2927" -t | geom combine | geom draw && open image.png
  36. 36. GeoScript: convert to kml echo "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>
  37. 37. GeoScript: draw shapefile geoscript-groovy -e "println new geoscript.geom.GeometryCollection(new geoscript.layer.Shapefile('states.shp').features.collect {it.geom}).wkt" | geom draw && open image.png
  38. 38. GeoScript: write shapefile echo "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)})"
  39. 39. Geocoding curl "http://geocoder.us/service/csv/geocode?zip=95472" | awk -F ", " '{print "POINT ("$2 " " $1 ")"}' | geom buffer -d 10 | geom draw && open image.png
  40. 40. USGS Earthquakes curl 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
  41. 41. WMS curl -o map.jpg "http://vmap0.tiles.osgeo.org/wms/vmap0? LAYERS=basic&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetM ap&STYLES=&FORMAT=image%2Fjpeg&SRS=EPSG %3A4326&BBOX=-123.07,46.66,-121.14,47.48&WIDTH=500&HEIG HT=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
  42. 42. Install • Install Java • Download • https://github.com/jericks/geometrycommands/ downloads • Put on path • export PATH = /whereever/you/put/it/geom/bin
  43. 43. Help • View commands • geom list • Get help on a command • geom buffer --help • Man pages • man geom • man geom-buffer
  44. 44. Web Site (Sphinx)
  45. 45. 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)
  46. 46. Thank you!

×