Factual / geo

Clojure library for working with geohashes, polygons, and other world geometry
Eclipse Public License 1.0
301 stars 17 forks source link

io/read-geojson throws error #11

Closed rrrnld closed 6 years ago

rrrnld commented 6 years ago
(-> (slurp "https://gist.githubusercontent.com/heyarne/09812024067c4db239df2181c347f743/raw/a9a372710097e4d2c3df699e3b84cdfd1526eb7e/isochrones-galton-lat:52.5219184-lng:13.4132147.geojson")
  (io/read-geojson))

throws the following exception:

Exception thrown: java.lang.NoSuchMethodError (com.fasterxml.jackson.databind.JavaType.isReferenceType()Z)

    _createDeserializer2 - (DeserializerCache.java:397)
    _createDeserializer - (DeserializerCache.java:349)
    _createAndCache2 - (DeserializerCache.java:264)
    _createAndCacheValueDeserializer - (DeserializerCache.java:244)
    findValueDeserializer - (DeserializerCache.java:142)
    findRootValueDeserializer - (DeserializationContext.java:476)
    _findRootDeserializer - (ObjectMapper.java:3899)
    _readMapAndClose - (ObjectMapper.java:3794)
    readTree - (ObjectMapper.java:2381)
    create - (GeoJSONFactory.java:21)
    read - (GeoJSONReader.java:16)
    read-geojson - geo.io - (io.clj:23)
    read-geojson - geo.io - (io.clj:23)
    eval12767 - rbb-data.gorilla.map-view - (form-init8373600070398405018.clj:1)
    eval12767 - rbb-data.gorilla.map-view - (form-init8373600070398405018.clj:1)

My project.clj:

(defproject not-important "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.8.0"]
                 [factual/geo "1.2.0"]
                 [dk.ative/docjure "1.12.0"]]
  :plugins [[lein-gorilla "0.4.0"]]
  :main ^:skip-aot not-important.core
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all}})

Environment info:

❯ system_profiler SPSoftwareDataType
Software:

    System Software Overview:

      System Version: macOS 10.13.4 (17E199)
      Kernel Version: Darwin 17.5.0
      Boot Volume: Macintosh HD
      Boot Mode: Normal

❯ java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
worace commented 6 years ago

@heyarne thanks for reporting this. Unfortunately the geojson reader we are using at the moment (which is just the built-in JTS GeoJSONReader) does not handle Features or FeatureCollections -- only basic geometries.

It looks like some libraries (e.g. https://github.com/bjornharrtell/jts2geojson) do handle these by doing some extra processing before converting them to geometries. I'll have to do a bit of research to see if this is something we can incorporate cleanly.

willcohen commented 6 years ago

jts2geojson has now been updated to JTS 1.15 and a release was cut two days ago, so it doesn't conflict anymore.

Does it make sense that we re-add jts2geojson so that we can read and write these collections, but also keep the JTS io library so that we can do things like the EWKB (being discussed now in #10)?

@heyarne @worace

willcohen commented 6 years ago

12 should work correctly on the proposed example. It returns a list containing two Polygons and a MultiPolygon. @heyarne @worace

willcohen commented 6 years ago

I think the actual error reported might not be about the Feature/FeatureCollection issue (which throws an UnsupportedOperationException for me when using geo 1.2.0), and as discussed above, changes are indeed needed to successfully parse the geojson listed in the example.

gorilla-repl 0.4.0 uses cheshire 5.3.1 which uses jackson 2.3.1, which would lead to the MethodError reported (see #13). Solving this may require either excluding gorilla-repl or getting it to use a newer version of cheshire.

willcohen commented 6 years ago

Is this issue resolved?

(-> (slurp "https://gist.githubusercontent.com/heyarne/09812024067c4db239df2181c347f743/raw/a9a372710097e4d2c3df699e3b84cdfd1526eb7e/isochrones-galton-lat:52.5219184-lng:13.4132147.geojson")
    (read-geojson)
    (nth 2))
=>
{:properties {:time 30},
 :geometry #object[org.locationtech.jts.geom.MultiPolygon
                   0x5caf2c13
                   "MULTIPOLYGON (((13.323281 52.544492, 13.324786 52.541774, 13.325686 52.543418, 13.324889 52.54385, 13.323324 52.550874, 13.323415 52.550102, 13.323281 52.544492)), ((13.407952 52.465478, 13.398501 52.466007, 13.402426 52.465567, 13.402496 52.465578, 13.404727 52.465363, 13.407952 52.465478)))"]}
rrrnld commented 6 years ago

Just tried it via clj -Sdeps '{:deps {factual/geo {:mvn/version "2.0.0-rc-3"}}}, works like a charm! Thanks a lot!