ewestern / geos Goto Github PK
View Code? Open in Web Editor NEWThis is a Haskell binding to Geos, the open-source geometry library
License: MIT License
This is a Haskell binding to Geos, the open-source geometry library
License: MIT License
Hey there,
thanks for the package.
The function Data.Geometry.Geos.STRTree.insert has the following type signature
insert :: Storable a => Geometry b -> a -> STRTreeBuilder a -> ()
which looks very suspicious. Either this function has no effect at all or it has some hidden IO in which it modifies the passed builder.
This seems to be indeed the case and it's easy to make the library crash
λ> import Data.Geometry.Geos.STRTree
λ> import Data.Geometry.Geos.Geometry
λ> p = PointGeometry (point $ coordinate2 0.1 0.2) Nothing
λ> empty
STRTreeBuilder 0x0000000000eb5ff0
λ> insert p 1 empty
()
λ> toList (build empty)
[()]
λ> insert p 1 empty
ghc: AbstractSTRtree.cpp:115: virtual void geos::index::strtree::AbstractSTRtree::insert(const void*, void*): Assertion `!built' failed.
cabal: repl failed for fake-package-0. The build process terminated with exit
code -6
Hi,
I wanted to know the format read by GEOS.Serialize.readHex.
If I understand correcty, it's a .wbk file in base 16 (hexadecimal).
I've got issues reading my own file with that lib.
I noticed distance
is documented to not support geographic coordinate systems, so my followup question is what level of support this library has for geographic coordinate systems, and if any of the currently missing support is planned/desired.
Hi,
I'm having real problems with MultiPolygons which I think I have reproduced in the tests (branch PR is here: #3)
Basically the following hex encodes a multi polygon
0106000020e6100000020000000103000000010000002e0000001826530523256340321ea5129e603bc0e7e26f7b8223634005a568e55e703bc0cade52ce97216340534145d5af703bc0d38558fd9121634051f4c0c760793bc04eb857e62d21634004711e4e60763bc09a42e735f620634071ab2006ba7a3bc09e616a4b1d206340906ad8ef89793bc0f3e84658d41f63402159c0046e7d3bc0d3d9c9e0a8206340709692e524803bc0226e4e25032063404f57772cb6813bc048c2be9d4420634023a46e675f853bc0994869360f1f6340c6f7c5a52a813bc0e605d847271f6340d28f8653e68a3bc08ac745b5081e634025b1a4dc7d863bc01ec539eae81c6340406ce9d1548b3bc0b84082e2c71c6340ed832c0b269a3bc022aaf067f81b63405c72dc291d943bc07a7077d66e1b63400d1afa27b8983bc035b22b2d231b6340882cd2c43b883bc0c828cfbc9c1a63401616dc0f78883bc03a5cab3dec1a6340ddcd531d728b3bc0378b170b431a634024d5777e518e3bc0cbf6216fb9176340de3d40f7e5903bc050508a56ee1763401cb5c2f4bd863bc0f4311f1068186340772b4b7496853bc09b560a815c17634064ac36ffaf7e3bc0e15e99b7ea17634077f35487dc703bc0fce4284094176340a9177c9a935f3bc0a530ef71a6166340bc9179e40f5a3bc03eca880bc0156340087250c24c5f3bc0f8e0b54b1b166340c4b0c398f4573bc05e2a36e6f5176340af08feb792513bc07a3881e9b41863400a2fc1a90f583bc0dc813ae55118634008e753c72a5d3bc04208c897d0186340ff3d78edd2663bc030849cf7ff196340ed647094bc663bc0d653abaf2e1b6340a69718cbf46b3bc0bb809719b61c63405f46b1dcd26a3bc03eeaaf57581d634000ac8e1ce9643bc0fa5e43705c1e634003eb387ea8683bc0e9edcf45431f6340b073d3669c663bc05f27f565e91f6340211ff46c564d3bc09f909db731226340e3a9471adc463bc0b212f3aca4226340d0b7054b75553bc0f14a92e7fa2463406571ff91e95c3bc01826530523256340321ea5129e603bc00103000000010000000b00000003b16ce610236340779fe3a3c5413bc01b2c9ca479226340dae731ca33433bc0221add416c22634083fa96395d3a3bc0ee5d83be74216340acaa97df693a3bc04b5af10d052163403140a20914353bc062dba2cc86216340dc2a8881ae313bc06953758fec22634078b988efc4343bc0569e40d8a9236340e2afc91af5303bc0478e7406c6236340807d74eaca3b3bc054e4107173236340d7868a71fe423bc003b16ce610236340779fe3a3c5413bc0
which looks like this when it's parsed
MULTIPOLYGON(((153.160525 -27.377412,153.109678 -27.438948,153.049781 -27.440183,153.049071 -27.474133,153.036853 -27.462407,153.030055 -27.479401,153.003576 -27.474761,152.994671 -27.48996,153.020615 -27.500563,153.000384 -27.506686,153.008376 -27.520987,152.970607 -27.504557,152.973545 -27.542577,152.938563 -27.525358,152.903432 -27.544263,152.8994 -27.602143,152.874073 -27.57857,152.85728 -27.59656,152.848044 -27.532162,152.831633 -27.533082,152.841338 -27.54471,152.820684 -27.555931,152.741386 -27.566009,152.747844 -27.526336,152.762703 -27.521827,152.730042 -27.494873,152.747402 -27.440865,152.736847 -27.373346,152.707818 -27.351805,152.679693 -27.372265,152.690832 -27.343576,152.748767 -27.318645,152.772084 -27.343989,152.759997 -27.363934,152.775463 -27.401656,152.812496 -27.401315,152.849449 -27.421704,152.897229 -27.41728,152.917034 -27.394182,152.948784 -27.408821,152.976962 -27.400824,152.997241 -27.3021,153.068569 -27.276796,153.082602 -27.333821,153.155628 -27.362939,153.160525 -27.377412)),((153.095813 -27.256922,153.077349 -27.262509,153.075715 -27.227985,153.045501 -27.228178,153.031867 -27.207337,153.047705 -27.194069,153.091377 -27.20613,153.114483 -27.19124,153.117923 -27.233565,153.107842 -27.261695,153.095813 -27.256922)))
But testing this seems to cause seg faults.
Happy to help with debugging this but don't really know where to start.
Hi there!
First off, thanks for this great library!
I am having a hard time trying to extract the coordinates out of a 'Geometry Polygon'. Unfortunately I get a null pointer exception. Please see the minimal ghci-demo I've created to illustrate the problem:
Prelude> :l GetCoordSeqDemo.hs
[1 of 1] Compiling GetCoordSeqDemo ( GetCoordSeqDemo.hs, interpreted )
Ok, one module loaded.
*GetCoordSeqDemo> testCoordSeqGetter $ getPgRawGeom createPg
*** Exception: Encountered null pointer at: getCoordinateSequence
CallStack (from HasCallStack):
error, called at src/Data/Geometry/Geos/Raw/Base.hs:68:14 in geos-0.4.1-ABmO5CcGEiV20rMbTpIAA0:Data.Geometry.Geos.Raw.Base
And this would be the content of GetCoordSeqDemo.hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
module GetCoordSeqDemo where
import qualified Data.Vector as V
import Data.Geometry.Geos.Geometry
import qualified Data.Geometry.Geos.Raw.Base as RB
import qualified Data.Geometry.Geos.Raw.CoordSeq as RC
import qualified Data.Geometry.Geos.Raw.Geometry as R
-- stolen from Helpers.hs
makeLinearRing :: [(Double, Double)] -> Either GeometryConstructionError LinearRing
makeLinearRing = linearRing . V.map (uncurry coordinate2) . V.fromList
makePolygon :: [[(Double, Double)]] -> Either GeometryConstructionError Polygon
makePolygon ls = do
lRings <- traverse makeLinearRing ls
polygon $ V.fromList lRings
makePolygonGeo :: [[(Double, Double)]] -> Either GeometryConstructionError (Geometry Polygon)
makePolygonGeo cs = (\pg -> PolygonGeometry pg Nothing) <$> makePolygon cs
fromRight :: Either a b -> b
fromRight (Right v) = v
fromRight _ = error "Shouldn't happen."
-- demo starts here
createPg :: Geometry Polygon
createPg = (fromRight . makePolygonGeo) [[(1.1,1.2),(22.1,22.2),(33.1,33.2),(1.1,1.2)]]
getPgRawGeom :: Geometry Polygon -> R.GeomConst
getPgRawGeom geometryPg = RB.runGeos $ do
geometryP' :: R.GeomConst <- convertGeometryToRaw geometryPg
return geometryP'
testCoordSeqGetter :: R.Geometry a => a -> RC.CoordSeq
testCoordSeqGetter geom = RB.runGeos $ do
R.getCoordinateSequence geom
Since I am relatively new to Haskell I am not sure if I am doing sth. terribly wrong here or if I found a bug. Any help would be appreciated!
The lack of Generic instances makes the lack of other instances like FromJSON and ToJSON a lot more painful, as you either need orphans or handwritten instances. Adding Generic instances doesn't require adding any new dependencies, so it seems like a worthwhile addition to me.
I created a small postgis library for persistent here and for esqueleto here. I am now realizing that it seems like it might be better to build off of or just use geos
directly.
I was wondering if the instances could be added into geos
itself, although I realize the dependency on persistent/esqueleto might make it not worth it.
My primary usage for geos
is for Geographies rather than Geometries, and I'm not 100% clear on the amount of compatibility / overlap between the two. But ideally I was hoping that all the types I have in persistent-postgis including their associated db types could be converted over in some form into geos
, perhaps involving some type level machinary to allow for easily defining both the geometry and the geography versions of the type. I was similarly hoping for support for some SQL queries like ST_Intersects via esqueleto.
It seems like readHex
and writeHex
do correctly support Ewkb
, or at least I have been able to parse and re-serialize hex strings from geographic data stored in postgis geographic types. However the documentation does not mention it anywhere, so assuming that it is supported that would be a great thing to mention.
Hi, have a Point and I'm looking to get the underlying coordinate out of it, so I can format the x/y coordinates how my web frontend expects it.
As far as I can tell, this requires dipping down into the Raw modules. Would you accept a PR that exposed the newtype constructor for Point
to allow unwrapping, or a PR that added a pointToCoordinate :: Point -> Coordinate
function?
I might just be totally missing an obvious way to do this, if so sorry!
#35 seems like a similar issue
Hello.
I tried to install geos by cabal, but failed. I suppose that install-includes
is needed in the geos.cabal
file.
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.0.1
$ cabal --version
cabal-install version 2.0.0.1
compiled using version 2.0.1.1 of the Cabal library
OS X 10.10.5
$ cabal install geos
Warning: --root-cmd is no longer supported, see
https://github.com/haskell/cabal/issues/3353 (if you didn't type --root-cmd,
comment out root-cmd in your ~/.cabal/config file)
Resolving dependencies...
Notice: installing into a sandbox located at
/.cabal-sandbox
Configuring geos-0.1.1.1...
Building geos-0.1.1.1...
Failed to install geos-0.1.1.1
Build log ( /Users/.cabal-sandbox/logs/ghc-8.0.1/geos-0.1.1.1-BMEKj1bfr4oGwvlkBjY7fl.log ):
cabal: Entering directory '/var/folders/hw/p4bp49hd7v9_1j60sjvmhqnr0000gn/T/cabal-tmp-27304/geos-0.1.1.1'
Configuring geos-0.1.1.1...
Preprocessing library for geos-0.1.1.1..
Internal.hsc:9:10: fatal error: 'noticehandlers.h' file not found
#include "noticehandlers.h"
^
1 error generated.
compiling dist/dist-sandbox-ce0620c0/build/Data/Geometry/Geos/Raw/Internal_hsc_make.c failed (exit code 1)
command was: /usr/bin/gcc -c dist/dist-sandbox-ce0620c0/build/Data/Geometry/Geos/Raw/Internal_hsc_make.c -o dist/dist-sandbox-ce0620c0/build/Data/Geometry/Geos/Raw/Internal_hsc_make.o -m64 -fno-stack-protector -m64 -fno-stack-protector -m64 -D__GLASGOW_HASKELL__=800 -Ddarwin_BUILD_OS=1 -Dx86_64_BUILD_ARCH=1 -Ddarwin_HOST_OS=1 -Dx86_64_HOST_ARCH=1 -Icbits -fPIC -Idist/dist-sandbox-ce0620c0/build/autogen -Idist/dist-sandbox-ce0620c0/build/global-autogen -include dist/dist-sandbox-ce0620c0/build/autogen/cabal_macros.h -I/Users/.cabal-sandbox/lib/x86_64-osx-ghc-8.0.1/vector-0.12.0.1-JOtbAphig5lG2Gp1CUS1Dj/include -I/Users/.cabal-sandbox/lib/x86_64-osx-ghc-8.0.1/primitive-0.6.2.0-3HSsNCfUEEE4fjqDYVydYZ/include -I/Library/Frameworks/GHC.framework/Versions/8.0.1-x86_64/usr/lib/ghc-8.0.1/bytestring-0.10.8.1/include -I/Library/Frameworks/GHC.framework/Versions/8.0.1-x86_64/usr/lib/ghc-8.0.1/base-4.9.0.0/include -I/Library/Frameworks/GHC.framework/Versions/8.0.1-x86_64/usr/lib/ghc-8.0.1/integer-gmp-1.0.0.1/include -I/Library/Frameworks/GHC.framework/Versions/8.0.1-x86_64/usr/lib/ghc-8.0.1/include -I/Library/Frameworks/GHC.framework/Versions/8.0.1-x86_64/usr/lib/ghc-8.0.1/include/
cabal: Leaving directory '/var/folders/hw/p4bp49hd7v9_1j60sjvmhqnr0000gn/T/cabal-tmp-27304/geos-0.1.1.1'
cabal: Error: some packages failed to install:
geos-0.1.1.1-BMEKj1bfr4oGwvlkBjY7fl failed during the building phase. The
exception was:
ExitFailure 1
Data.Geometry.Geos.Geometry
contains the Coordinate data type here
geos/src/Data/Geometry/Geos/Geometry.hs
Lines 79 to 81 in aa196ae
but Coordinate
isn't in the module's export list. This makes it impossible to construct e.g. a Point
by hand.
GHC 8.4 implements the Semigroup-Monoid proposal which makes Semigroup a superclass of Monoid. In GHC 8.4 I get this error:
src/Data/Geometry/Geos/Types.hs:70:10: error:
• No instance for (Semigroup LinearRing)
arising from the superclasses of an instance declaration
• In the instance declaration for ‘Monoid LinearRing’
|
70 | instance Monoid LinearRing where
| ^^^^^^^^^^^^^^^^^
Which corresponds to this declaration
geos/src/Data/Geometry/Geos/Geometry.hs
Lines 100 to 102 in e9cff92
The wiki has suggestions for writing compatible code.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.