Giter Site home page Giter Site logo

paulsmith / gogeos Goto Github PK

View Code? Open in Web Editor NEW
277.0 8.0 80.0 584 KB

Go library for spatial data operations and geometric algorithms (Go bindings for GEOS)

Home Page: http://paulsmith.github.io/gogeos/

License: MIT License

Go 95.47% C 0.75% Python 3.78%

gogeos's Introduction

gogeos - Go library for spatial data operations and geometric algorithms

Build Status

gogeos is a library for Go that provides operations on spatial data and geometric algorithms.

It provides bindings to the GEOS C library.

Quick start

package main

import (
	"fmt"

	"github.com/paulsmith/gogeos/geos"
)

func main() {
	line, _ := geos.FromWKT("LINESTRING (0 0, 10 10, 20 20)")
	buf, _ := line.Buffer(2.5)
	fmt.Println(buf)
	// Output: POLYGON ((18.2322330470336311 21.7677669529663689, 18.61…
}

Overview

Functionality

  • Binary predicates - intersects, disjoint, etc.
  • Topology operations - difference, union, etc.
  • Polygonization, line merging, and simplification
  • Prepared geometries (for better performance for common binary predicates)
  • Validity checking
  • DE-9IM
  • Geometry info - area, length, distance, etc.
  • IO - WKT & WKB read/write

gogeos is an open source project.

Community

Installation

Requirements

  • GEOS 3.3.8 or 3.3.9

GEOS must be installed on your system to build gogeos.

Ubuntu

$ apt-get install libgeos-dev

OS X - homebrew

$ brew install geos

From source (all OSes)

$ wget http://download.osgeo.org/geos/geos-3.3.8.tar.bz2
$ tar xvfj geos-3.3.8.tar.bz2
$ cd geos-3.3.8
$ ./configure
$ make
$ sudo make install

Installing gogeos

$ go get github.com/paulsmith/gogeos/geos

Documentation

Example

Let’s say you have two polygons, A (blue) and B (orange).

One of the most common things to do with a spatial data library like gogeos is compute the intersection of two or more geometries. Intersection is just a method on geometry objects in gogeos, which takes one argument, the other geometry, and computes the intersection with the receiver. The result is a new geometry, C (magenta):

C := geos.Must(A.Intersection(B))

geos.Must is just a convenience function that takes the output of any gogeos function or method that returns a geometry and an error. It panics if the error is non-null, otherwise returning the geometry, making it more convenient to use in single-value contexts. In production code, though, you’ll want to check the error value.

(NB: these graphics weren't produced by gogeos directly - I used the excellent draw2d package to render the output of gogeos functions.)

License

MIT. See COPYING.

Copyright (c) 2013 Paul Smith

gogeos's People

Contributors

bdon avatar paulsmith avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gogeos's Issues

Fixed a bug in encodeWkb() for Windows

Found a bug in encodeWkb() for windows.
A buffer allocated in geos_c.dll whith malloc() cannot simply be freed with C.free(). Must use cGEOSFree().
Now all tests pass.
The modified code follows:

func encodeWkb(e *wkbEncoder, g *Geometry, fn func(*C.GEOSWKBWriter, *C.GEOSGeometry, *C.size_t) *C.uchar) ([]byte, error) {
    var size C.size_t
    bytes := fn(e.w, g.g, &size)
    if bytes == nil {
        return nil, Error()
    }
    ptr := unsafe.Pointer(bytes)
    defer cGEOSFree((*C.void)(ptr))     //instead of C.free(ptr)

    l := int(size)
    var out []byte

    for i := 0; i < l; i++ {
        el := unsafe.Pointer(uintptr(ptr) + unsafe.Sizeof(C.uchar(0))*uintptr(i))
        out = append(out, byte(*(*C.uchar)(el)))
    }

    return out, nil 
} 

go get exited with error

while doing go get as mentioned in read me got following error

go get github.com/paulsmith/gogeos/geos

In file included from ../../pkg/mod/github.com/paulsmith/[email protected]/geos/coordseq.go:4:
./geos.h:1:10: fatal error: 'geos_c.h' file not found
#include <geos_c.h>
         ^~~~~~~~~~
1 error generated.

WKT precision encode error

While creating new polygon using wkt, the results (error free) change the precision and the value of the points.

polygon, err := geos.FromWKT("POLYGON ((11.1 44.1, 12 45, 13 46, 11.1 44.1))")
fmt.Println(polygon)

the result is:

POLYGON ((11.0999999999999996 44.1000000000000014, 12.0000000000000000 45.0000000000000000, 13.0000000000000000 46.0000000000000000, 11.0999999999999996 44.1000000000000014))

The points are different

Panics on prepared geometry calls

I have observed panics when prepared geometry objects are used:

pure virtual method called
terminate called without an active exception
SIGABRT: abort
PC=0x7fbe473fbd27
signal arrived during cgo execution

goroutine 6 [syscall, locked to thread]:
runtime.cgocall_errno(0x408920, 0xc2080d9218, 0x0)
  $GOROOT/src/runtime/cgocall.go:130 +0xf5 fp=0xc2080d91f8 sp=0xc2080d91d0
github.com/paulsmith/gogeos/geos._Cfunc_GEOSPreparedCovers_r(0x2a7eb50, 0x7fbe3c127880, 0x2bb87e0, 0xc208034900)
  github.com/paulsmith/gogeos/geos/_obj/_cgo_gotypes.go:672 +0x40 fp=0xc2080d9218 sp=0xc2080d91f8
github.com/paulsmith/gogeos/geos.cGEOSPreparedCovers(0x7fbe3c127880, 0x2bb87e0, 0x4d3200)
  $GOPATH/src/github.com/paulsmith/gogeos/geos/cwrappers.go:547 +0x74 fp=0xc2080d9240 sp=0xc2080d9218
github.com/paulsmith/gogeos/geos.(*PGeometry).predicate(0xc20802e068, 0x7c8480, 0x6, 0x87a250, 0xc20802e600, 0x8, 0x0, 0x0)
  $GOPATH/src/github.com/paulsmith/gogeos/geos/prepared.go:95 +0x5b fp=0xc2080d92b0 sp=0xc2080d9240
github.com/paulsmith/gogeos/geos.(*PGeometry).Covers(0xc20802e068, 0xc20802e600, 0x348, 0x0, 0x0)
  $GOPATH/src/github.com/paulsmith/gogeos/geos/prepared.go:55 +0x63 fp=0xc2080d92f8 sp=0xc2080d92b0

I tried to recreate the behaviour in a test, but I couldn't, at least not consistently. It is related to Go's GC cycles and the finalizer calling cGEOSGeom_destroy(ptr) on the original Geometry. As a workaround, I added:

diff --git a/geos/prepared.go b/geos/prepared.go
index a7af6d1..3383fe8 100644
--- a/geos/prepared.go
+++ b/geos/prepared.go
@@ -14,12 +14,13 @@ import (
 // optimized for a limited set of operations.
 type PGeometry struct {
        p *C.GEOSPreparedGeometry
+       g *Geometry
 }

 // PrepareGeometry constructs a prepared geometry from a normal geometry object.
 func PrepareGeometry(g *Geometry) *PGeometry {
        ptr := cGEOSPrepare(g.g)
-       p := &PGeometry{ptr}
+       p := &PGeometry{ptr, g}
        runtime.SetFinalizer(p, (*PGeometry).destroy)
        return p
 }
@@ -27,6 +28,7 @@ func PrepareGeometry(g *Geometry) *PGeometry {
 func (p *PGeometry) destroy() {
        cGEOSPreparedGeom_destroy(p.p)
        p.p = nil
+       p.g = nil
 }

 // Prepared geometry binary predicates

It fixes the problem by preventing the Geometry from being garbage-collected, but it is not very elegant.

Thoughts? Thanks

Buffer options

  • # of quad segments
  • cap style
  • join style
  • mitre limit
  • single sided

Segmentation violation (reproducible)

Ignore this comment. Go to the update.

I'm sorry that this is going to be very vague but we haven't had the time to investigate too much.

The gist is, we have some gogeos WKT processing that pretty consistently crashes with a segmentation violation when compiled using 1.8.1. The same doesn't happen with 1.7.3.

The main diagnosis we tried was removing the concurrency, both with code changes and GOMAXPROCS=1 and various GOGC settings. It still seemed to consistently crash with 1.8.1.

We use a Dockerfile to compile the code to ensure that all the dependencies are stable between compilations.

One of the stacks:

fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x80 addr=0x0 pc=0x7f851a2f15f2]

runtime stack:
runtime.throw(0x97b351, 0x2a)
    /go/src/runtime/panic.go:596 +0x95
runtime.sigpanic()
    /go/src/runtime/signal_unix.go:274 +0x2db

goroutine 5789 [syscall, locked to thread]:
runtime.cgocall(0x85ca70, 0xc434b07d78, 0xc434b07da0)
    /go/src/runtime/cgocall.go:131 +0xe2 fp=0xc434b07d48 sp=0xc434b07d08
github.com/paulsmith/gogeos/geos._Cfunc_GEOSWKTReader_read_r(0x2adccf0, 0x7f850403d330, 0x7f850403d220, 0x0)
    github.com/paulsmith/gogeos/geos/_obj/_cgo_gotypes.go:2249 +0x4e fp=0xc434b07d78 sp=0xc434b07d48
github.com/paulsmith/gogeos/geos.cGEOSWKTReader_read.func1(0x2adccf0, 0x7f850403d330, 0x7f850403d220, 0xc429edf840)
    /src/github.com/paulsmith/gogeos/geos/cwrappers.go:871 +0xad fp=0xc434b07db0 sp=0xc434b07d78
github.com/paulsmith/gogeos/geos.cGEOSWKTReader_read(0x7f850403d330, 0x7f850403d220, 0x0)
    /src/github.com/paulsmith/gogeos/geos/cwrappers.go:871 +0x86 fp=0xc434b07de0 sp=0xc434b07db0
github.com/paulsmith/gogeos/geos.(*wktDecoder).decode(0xc430098b10, 0xc42a6e2bd0, 0x81, 0x0, 0x0, 0x0)
    /src/github.com/paulsmith/gogeos/geos/wkt.go:33 +0x9e fp=0xc434b07e10 sp=0xc434b07de0
github.com/paulsmith/gogeos/geos.FromWKT(0xc42a6e2bd0, 0x81, 0x81, 0x471f64, 0xc431037860)

The Dockerfile and build:

git clone https://gist.github.com/84ebf7c210c0b53ec971b7113b17a607.git
cd 84ebf7c210c0b53ec971b7113b17a607
make build
make run

(the main.go in that gist obviously doesn't represent our code which we can't post and haven't had time to create a reproducible case to post)

Linker error

I am getting the following error when trying to build:

/usr/local/Cellar/go/1.5.3/libexec/pkg/tool/darwin_amd64/link: running clang failed: exit status 1 ld: library not found for -lgeos_c clang: error: linker command failed with exit code 1 (use -v to see invocation)

This is probably user error of some sort, but I can't work out what I could have done to cause it. I'm on El Capitan.

Steps I've taken today:

  • Remove GEOS 3.5 (brew uninstall geos)
  • Install GEOS 3.3.9 from source as per the docs
  • Create a new project containing a single main.go with the quick start code from the docs
  • go get github.com/paulsmith/gogeos/geos
  • go build

Other things I have done:

  • look for rogue geos* files
    • temporarily renamed a directory called GEOS.framework (I can't remember what this was about)

Any suggestions on how I can proceed here?

libc++abi.dylib: Pure virtual function called

Hi,

Using this library under heavy load I received the following error.
Any info about the meaning of "Pure virtual function called" or hints on where to look in the code to fix this much appreciated 🙏

libc++abi.dylib: Pure virtual function called!
SIGABRT: abort
PC=0x7fff7391f33a m=10 sigcode=0

goroutine 0 [idle]:
runtime: unknown pc 0x7fff7391f33a
stack: frame={sp:0x700006ac0b78, fp:0x0} stack=[0x700006a41350,0x700006ac0f50)
0000700006ac0a78:  00007fff9a0b4920  0000000000000000
0000700006ac0a88:  00007fff9a0b4920  0000000000000c03
0000700006ac0a98:  00007fff9a0b4918  0000700006ac0ac0
0000700006ac0aa8:  0000700006ac0ae0  00007fff9a0b4920
0000700006ac0ab8:  0000000000000000  0000000032aaaba2
0000700006ac0ac8:  0000000000000000  0000000000000000
0000700006ac0ad8:  0000700006ac0c10  0000000000000000
0000700006ac0ae8:  0000000032aaaba2  0000000000000000
0000700006ac0af8:  0000000000000000  0000000000000000
0000700006ac0b08:  0000000000000000  0000000000000000
0000700006ac0b18:  0000000000000000  0000000000000000
0000700006ac0b28:  0000000000000003  0000000000000000
0000700006ac0b38:  0000000000000000  00007fff9a0b4ec0
0000700006ac0b48:  00007fff9a0b4930  00007fff73860065
0000700006ac0b58:  0000000000000000  0000700006ac0ba0
0000700006ac0b68:  00007fff738628ed  0000000000000000
0000700006ac0b78: <00007fff739dbe60  0000000000000003
0000700006ac0b88:  0000700006ac0d20  0000700006ac0bc0
0000700006ac0b98:  00007fff9a0b5620  0000700006ac0be0
0000700006ac0ba8:  00007fff738a6808  e509fd3029420036
0000700006ac0bb8:  0000700006ac0ce0  00007000fffff9df
0000700006ac0bc8:  ffffffff00000008  0000700006ac0ce0
0000700006ac0bd8:  00007fff70b08f23  0000700006ac0d10
0000700006ac0be8:  00007fff70b05458  0000003000000008
0000700006ac0bf8:  0000700006ac0d20  0000700006ac0c30
0000700006ac0c08:  000000000de48450  0000003000000008
0000700006ac0c18:  0000700006ac0d20  0000700006ac0c30
0000700006ac0c28:  00007fff7399303c  00000000000000b7
0000700006ac0c38:  000000002ff087c0  0000700006ac0d60
0000700006ac0c48:  00000000046f81e8  000000c000001500
0000700006ac0c58:  0000000000000000  00000000048d1600
0000700006ac0c68:  000000000de48330  0000000000000070
runtime: unknown pc 0x7fff7391f33a
stack: frame={sp:0x700006ac0b78, fp:0x0} stack=[0x700006a41350,0x700006ac0f50)
0000700006ac0a78:  00007fff9a0b4920  0000000000000000
0000700006ac0a88:  00007fff9a0b4920  0000000000000c03
0000700006ac0a98:  00007fff9a0b4918  0000700006ac0ac0
0000700006ac0aa8:  0000700006ac0ae0  00007fff9a0b4920
0000700006ac0ab8:  0000000000000000  0000000032aaaba2
0000700006ac0ac8:  0000000000000000  0000000000000000
0000700006ac0ad8:  0000700006ac0c10  0000000000000000
0000700006ac0ae8:  0000000032aaaba2  0000000000000000
0000700006ac0af8:  0000000000000000  0000000000000000
0000700006ac0b08:  0000000000000000  0000000000000000
0000700006ac0b18:  0000000000000000  0000000000000000
0000700006ac0b28:  0000000000000003  0000000000000000
0000700006ac0b38:  0000000000000000  00007fff9a0b4ec0
0000700006ac0b48:  00007fff9a0b4930  00007fff73860065
0000700006ac0b58:  0000000000000000  0000700006ac0ba0
0000700006ac0b68:  00007fff738628ed  0000000000000000
0000700006ac0b78: <00007fff739dbe60  0000000000000003
0000700006ac0b88:  0000700006ac0d20  0000700006ac0bc0
0000700006ac0b98:  00007fff9a0b5620  0000700006ac0be0
0000700006ac0ba8:  00007fff738a6808  e509fd3029420036
0000700006ac0bb8:  0000700006ac0ce0  00007000fffff9df
0000700006ac0bc8:  ffffffff00000008  0000700006ac0ce0
0000700006ac0bd8:  00007fff70b08f23  0000700006ac0d10
0000700006ac0be8:  00007fff70b05458  0000003000000008
0000700006ac0bf8:  0000700006ac0d20  0000700006ac0c30
0000700006ac0c08:  000000000de48450  0000003000000008
0000700006ac0c18:  0000700006ac0d20  0000700006ac0c30
0000700006ac0c28:  00007fff7399303c  00000000000000b7
0000700006ac0c38:  000000002ff087c0  0000700006ac0d60
0000700006ac0c48:  00000000046f81e8  000000c000001500
0000700006ac0c58:  0000000000000000  00000000048d1600
0000700006ac0c68:  000000000de48330  0000000000000070

goroutine 5 [syscall]:
runtime.cgocall(0x4260d60, 0xc0003d9ce0, 0xc0003d9d00)
	/usr/local/opt/go/libexec/src/runtime/cgocall.go:154 +0x5b fp=0xc0003d9cb0 sp=0xc0003d9c78 pc=0x400483b
github.com/paulsmith/gogeos/geos._Cfunc_GEOSWKBWriter_write_r(0xc008200, 0x2ff08c00, 0x2ff087c0, 0xc0003f26d0, 0x0)
	_cgo_gotypes.go:2221 +0x49 fp=0xc0003d9ce0 sp=0xc0003d9cb0 pc=0x418dfa9
github.com/paulsmith/gogeos/geos.cGEOSWKBWriter_write.func1(0x2ff08c00, 0x2ff087c0, 0xc0003f26d0, 0x8)
	/code/go/pkg/mod/github.com/paulsmith/[email protected]/geos/cwrappers.go:961 +0xc9 fp=0xc0003d9d20 sp=0xc0003d9ce0 pc=0x419e4e9
github.com/paulsmith/gogeos/geos.cGEOSWKBWriter_write(0x2ff08c00, 0x2ff087c0, 0xc0003f26d0, 0x0)
	/code/go/pkg/mod/github.com/paulsmith/[email protected]/geos/cwrappers.go:961 +0x8f fp=0xc0003d9d68 sp=0xc0003d9d20 pc=0x419434f
github.com/paulsmith/gogeos/geos.encodeWkb(0xc0003f26c8, 0xc0003f2680, 0x441d048, 0x0, 0x0, 0x0, 0x0, 0x0)
	/code/go/pkg/mod/github.com/paulsmith/[email protected]/geos/wkb.go:67 +0xa2 fp=0xc0003d9df0 sp=0xc0003d9d68 pc=0x4199382
github.com/paulsmith/gogeos/geos.(*wkbEncoder).encode(...)
	/code/go/pkg/mod/github.com/paulsmith/[email protected]/geos/wkb.go:83
github.com/paulsmith/gogeos/geos.(*Geometry).WKB(0xc0003f2680, 0x4408448, 0x6, 0x441cf30, 0xc0003f2650, 0x0)
	/code/go/pkg/mod/github.com/paulsmith/[email protected]/geos/geom.go:95 +0x45 fp=0xc0003d9e40 sp=0xc0003d9df0 pc=0x41946c5
...
uname -a
Darwin Peters-MacBook-Pro-2.local 19.6.0 Darwin Kernel Version 19.6.0: Thu Jun 18 20:49:00 PDT 2020; root:xnu-6153.141.1~1/RELEASE_X86_64 x86_64
grep paulsmith go.mod
	github.com/paulsmith/gogeos v0.1.2 // indirect
head $(brew --prefix geos)/ChangeLog
2021-02-10  Paul Ramsey <[email protected]>

	* NEWS: Update NEWS for 3.9.1

2021-02-09  Paul Ramsey <[email protected]>

	Merge branch '3.9' of https://git.osgeo.org/gitea/geos/geos into
	3.9

2021-02-09  Paul Ramsey <[email protected]>

possibly related: #29

geos undefined: coordSeq

when i try to install the package i get the following message

OS: ubuntu

go get github.com/paulsmith/gogeos/geos
/go/pkg/mod/github.com/paulsmith/[email protected]/geos/coord.go:23:21: undefined: coordSeq
/go/pkg/mod/github.com/paulsmith/[email protected]/geos/helper.go:5:14: undefined: Geometry
exit status 2

Beego Geometry Model Throwing Error (panic: reflect: call of reflect.Value.Interface on zero Value)

My Beego Model,

package models

import (
"github.com/astaxie/beego/orm"
_ "github.com/lib/pq"
// "time"
"github.com/paulsmith/gogeos/geos"
)

type Configuration struct {

Id int64 db:"id"
Created int64 db:"created_at";auto_now_add
Updated int64 db:"updated_at";auto_now
Tenant string db:"tenant",size=100
Role string db:"role",size=250
ServiceCode string db:"service_code",size=100
Url string db:url,size=512
Active bool db:is_active
Location string db:location
LocationGeom *geos.Geometry db:location_geom:default(geos.EmptyPolygon())
}

func init() {
// Need to register model in init
orm.RegisterModel( new(Configuration) )
}

I am getting the following Error on starting the application

panic: reflect: call of reflect.Value.Interface on zero Value

goroutine 1 [running]:
reflect.valueInterface(0x0, 0x0, 0x0, 0x1, 0x0, 0x0)
/usr/local/go/src/reflect/value.go:877 +0x90
reflect.Value.Interface(0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/reflect/value.go:872 +0x53
github.com/astaxie/beego/orm.getFieldType(0x45d4660, 0xc2080be070, 0xd6, 0x0, 0x0, 0x0)

exit status 3221225781

I am getting the following error when trying to execute go run main.go:

exit status 3221225781

main.go:

package main
import (
	"fmt"

	"github.com/paulsmith/gogeos/geos"
)
func main() {
	line, _ := geos.FromWKT("LINESTRING (0 0, 10 10, 20 20)")
	buf, _ := line.Buffer(2.5)
	fmt.Println(buf)
	// Output: POLYGON ((18.2322330470336311 21.7677669529663689, 18.61…
}

I don't know what happened,can you help me, thank you

Geometry.String() results in segmentation violation for MULTIPOLYGON

Geometry.String() works for POINT and LINEARRING, but results in a segmentation violation when called on a MULTIPOLYGON.

Code to reproduce:

triangle := geos.Must(geos.NewLinearRing(
	geos.NewCoord(0, 0),
	geos.NewCoord(1, 2),
	geos.NewCoord(2, 3),
	geos.NewCoord(0, 0),
))
multi := geos.Must(geos.NewCollection(geos.MULTIPOLYGON, triangle))
fmt.Printf("Triangle: %s\n", triangle.String())
fmt.Printf("Multi: %s\n", multi.String())

Result:

Triangle: LINEARRING (0.0000000000000000 0.0000000000000000, 1.0000000000000000 2.0000000000000000, 2.0000000000000000 3.0000000000000000, 0.0000000000000000 0.0000000000000000)
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x424ae24]

runtime stack:
runtime.throw(0x40d876b, 0x2a)
        /usr/local/go/src/runtime/panic.go:617 +0x72
runtime.sigpanic()
        /usr/local/go/src/runtime/signal_unix.go:374 +0x4a9

goroutine 1 [syscall]:
runtime.cgocall(0x409c2a0, 0xc000059dd0, 0x436ad98)
        /usr/local/go/src/runtime/cgocall.go:128 +0x5b fp=0xc000059da0 sp=0xc000059d68 pc=0x40044cb
github.com/paulsmith/gogeos/geos._Cfunc_GEOSWKTWriter_write_r(0x5800000, 0x5000250, 0x5000168, 0x0)
        _cgo_gotypes.go:2371 +0x4e fp=0xc000059dd0 sp=0xc000059da0 pc=0x40973ae
github.com/paulsmith/gogeos/geos.cGEOSWKTWriter_write.func1(0x5000250, 0x5000168, 0x419e5c8)
        /Users/ocean/go/pkg/mod/github.com/paulsmith/[email protected]/geos/cwrappers.go:889 +0xcb fp=0xc000059e10 sp=0xc000059dd0 pc=0x4098edb
github.com/paulsmith/gogeos/geos.cGEOSWKTWriter_write(0x5000250, 0x5000168, 0x0)
        /Users/ocean/go/pkg/mod/github.com/paulsmith/[email protected]/geos/cwrappers.go:889 +0x7a fp=0xc000059e38 sp=0xc000059e10 pc=0x4097e6a
github.com/paulsmith/gogeos/geos.(*wktEncoder).encode(0xc0000aa040, 0xc0000aa028, 0x0, 0xb2, 0xc0000c0000, 0x0)
        /Users/ocean/go/pkg/mod/github.com/paulsmith/[email protected]/geos/wkt.go:62 +0x3f fp=0xc000059e60 sp=0xc000059e38 pc=0x409870f
github.com/paulsmith/gogeos/geos.(*Geometry).ToWKT(0xc0000aa028, 0xc0000b0000, 0x40d3934, 0xd, 0xc000059f78)
        /Users/ocean/go/pkg/mod/github.com/paulsmith/[email protected]/geos/geom.go:79 +0x31 fp=0xc000059ea0 sp=0xc000059e60 pc=0x4097fc1
github.com/paulsmith/gogeos/geos.(*Geometry).String(...)
        /Users/ocean/go/pkg/mod/github.com/paulsmith/[email protected]/geos/geom.go:85
main.main()

cwrappers.go uses *C.void instead of unsafe.Pointer

The Go equivalent to C's void* type is unsafe.Pointer, and the cgo tool automatically wraps functions that accept or return void* to accept or return unsafe.Pointer instead.

cwrappers.go currently includes some functions that accept *C.void arguments, but none of them are actually called. If they were, you would likely find that the call sites require two conversions (to unsafe.Pointer and then to *C.void) where they should need only one (to unsafe.Pointer).

cgo runtime panic

Under heavy load gogoes/cgo randomly panics and outputs panic: runtime error: invalid memory address or nil pointer dereference. I can't tell if this is in gogeos or cgo, so I though I'd report it here first.

go version go1.3rc1 darwin/amd64

Code to reproduce:

package main

import (
    "fmt"
    "github.com/paulsmith/gogeos/geos"
)

func main() {
    for i := 0; i < 100000; i++ {
        geom, _ := geos.FromWKT("LINESTRING (0 0, 10 10, 20 20)")
        bounds, _ := geom.Envelope()
        shell, _ := bounds.Shell()
        points, _ := shell.NPoint()

        for j := 0; j < points; j++ {
            point, _ := shell.Point(j)
            x, _ := point.X()
            y, _ := point.Y()

            if x == -1 && y == -1 {
                fmt.Println("Never called")
            }
        }
    }
}

Stack (line 17 is x, _ := point.X()):

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x4048c30]

goroutine 16 [running]:
runtime.panic(0x40d4600, 0x4187c04)
    /usr/local/go/src/pkg/runtime/panic.c:279 +0xf5
github.com/paulsmith/gogeos/geos.(*Geometry).float64FromC(0x0, 0x40e8530, 0x1, 0x41194b0, 0xffffffff, 0x0, 0x0, 0x0)
    /Users/johnclark/go/src/github.com/paulsmith/gogeos/geos/geom.go:904 +0x50
github.com/paulsmith/gogeos/geos.(*Geometry).X(0x0, 0x2, 0x0, 0x0)
    /Users/johnclark/go/src/github.com/paulsmith/gogeos/geos/geom.go:704 +0x68
main.main()
    /Users/johnclark/go/src/github.com/genealogysystems/flechette/bug.go:17 +0xc5

goroutine 19 [finalizer wait]:
runtime.park(0x40157e0, 0x41a4fd8, 0x4189cc9)
    /usr/local/go/src/pkg/runtime/proc.c:1369 +0x89
runtime.parkunlock(0x41a4fd8, 0x4189cc9)
    /usr/local/go/src/pkg/runtime/proc.c:1385 +0x3b
runfinq()
    /usr/local/go/src/pkg/runtime/mgc0.c:2644 +0xcf
runtime.goexit()
    /usr/local/go/src/pkg/runtime/proc.c:1445

goroutine 17 [syscall]:
runtime.goexit()
    /usr/local/go/src/pkg/runtime/proc.c:1445
exit status 2

How did you render examples?

Hello! First of all, thank you for your great library!

Can you explain (or show an example of code) please how did you render examples from geometry objects?

Thank you!

WKB encoding/decoding

I noticed that wkb encoding/decoding seems to be implemented but not accessible from the exported api.

A FromWKB and ToWKB would be great.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.