Skip to content

Commit

Permalink
PDOK-14231
Browse files Browse the repository at this point in the history
Als OZON wil ik uitgefilterde geometrieën geaggregeerd kunnen weergeven (POC)
  • Loading branch information
Dominik Kepinski committed Jul 6, 2022
1 parent cab201b commit ab40288
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 40 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ require (
github.com/urfave/cli/v2 v2.8.1
)

require github.com/twpayne/go-geom v1.4.1

require (
github.com/gdey/errors v0.0.0-20190426172550-8ebd5bc891fb // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
Expand Down
57 changes: 57 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,34 +1,91 @@
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
github.com/DATA-DOG/go-sqlmock v1.3.2/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk=
github.com/arolek/p v0.0.0-20191103215535-df3c295ed582/go.mod h1:JPNItmi3yb44Q5QWM+Kh5n9oeRhfcJzPNS90mbLo25U=
github.com/cenkalti/backoff/v3 v3.0.0/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs=
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/gdey/errors v0.0.0-20190426172550-8ebd5bc891fb h1:FYO+lZtAUnakgSW9xYs7QvgawjCDM5wgHaXoDhYHNH4=
github.com/gdey/errors v0.0.0-20190426172550-8ebd5bc891fb/go.mod h1:PFaV7MgSRe92Wo9O2H2i1CIm7urUk10AgdSHKyBfjmQ=
github.com/go-spatial/geom v0.0.0-20220426070044-6e8855d2cfe6 h1:tTSXyqPd678jHHJgxIkWJAr5agI526nKm+22FHDVA94=
github.com/go-spatial/geom v0.0.0-20220426070044-6e8855d2cfe6/go.mod h1:YU06tBGGstQCUX7vMuyF44RRneTdjGxOrp8OJHu4t9Q=
github.com/go-spatial/proj v0.2.0/go.mod h1:ePHHp7ITVc4eIVW5sgG/0Eu9RMAGOQUgM/D1ZkccY+0=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/huandu/xstrings v1.3.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/lib/pq v0.0.0-20180327071824-d34b9ff171c2/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.8.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mattn/go-sqlite3 v1.12.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/mattn/go-sqlite3 v1.14.13 h1:1tj15ngiFfcZzii7yd82foL+ks+ouQcj8j/TPq3fk1I=
github.com/mattn/go-sqlite3 v1.14.13/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/goveralls v0.0.3-0.20180319021929-1c14a4061c1c/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw=
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/opencontainers/runc v1.0.0-rc9/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U=
github.com/ory/dockertest/v3 v3.6.0/go.mod h1:4ZOpj8qBUmh8fcBSVzkH2bws2s91JdGvHUqan4GHEuQ=
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/twpayne/go-geom v1.4.1 h1:LeivFqaGBRfyg0XJJ9pkudcptwhSSrYN9KZUW6HcgdA=
github.com/twpayne/go-geom v1.4.1/go.mod h1:k/zktXdL+qnA6OgKsdEGUTA17jbQ2ZPTUa3CCySuGpE=
github.com/twpayne/go-kml v1.5.2/go.mod h1:kz8jAiIz6FIdU2Zjce9qGlVtgFYES9vt7BTPBHf5jl4=
github.com/twpayne/go-polyline v1.0.0/go.mod h1:ICh24bcLYBX8CknfvNPKqoTbe+eg+MX1NPyJmSBo7pU=
github.com/twpayne/go-waypoint v0.0.0-20200706203930-b263a7f6e4e8/go.mod h1:qj5pHncxKhu9gxtZEYWypA/z097sxhFlbTyOyt9gcnU=
github.com/urfave/cli/v2 v2.8.1 h1:CGuYNZF9IKZY/rfBe3lJpccSoIY1ytfvmgQT90cNOl4=
github.com/urfave/cli/v2 v2.8.1/go.mod h1:Z41J9TPoffeoqP0Iza0YbAhGvymRdZAd2uPmZ5JxRdY=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191003171128-d98b1b443823/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200121082415-34d275377bf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20191114222411-4191b8cbba09/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
17 changes: 15 additions & 2 deletions pkg/gpkg/gpkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ func (f *featureGPKG) UpdateGeometry(geometry geom.Geometry) {
f.geometry = geometry
}

func (f *featureGPKG) IsReduced(isReduced bool) {
f.columns = append(f.columns, isReduced)
}

type column struct {
cid int
name string
Expand Down Expand Up @@ -323,6 +327,10 @@ func (t Table) selectSQL() string {
// build the INSERT statement based on the table and columns
func (t Table) insertSQL() string {
var csql, vsql []string
t.columns = append(t.columns, column{
name: "isReduced",
ctype: "BOOLEAN",
})
for _, c := range t.columns {
if c.name != t.gcolumn {
csql = append(csql, c.name)
Expand Down Expand Up @@ -374,6 +382,10 @@ func getTableColumns(h *gpkg.Handle, table string) []column {

// buildTable creates a given destination table with the necessary gpkg_ information
func buildTable(h *gpkg.Handle, t Table) error {
t.columns = append(t.columns, column{
name: "isReduced",
ctype: "BOOLEAN",
})
query := t.createSQL()
_, err := h.Exec(query)
if err != nil {
Expand All @@ -385,8 +397,9 @@ func buildTable(h *gpkg.Handle, t Table) error {
ShortName: t.Name,
Description: t.Name,
GeometryField: t.gcolumn,
GeometryType: t.gtype,
SRS: int32(t.srs.ID),
// as sieved geometry is reduced to a POINT, it is necessary to allow multiple geometry types
GeometryType: gpkg.Geometry,
SRS: int32(t.srs.ID),
//
Z: gpkg.Prohibited,
M: gpkg.Prohibited,
Expand Down
1 change: 1 addition & 0 deletions pkg/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type Feature interface {
Columns() []interface{}
Geometry() geom.Geometry
UpdateGeometry(geom.Geometry)
IsReduced(bool)
}

type Source interface {
Expand Down
103 changes: 84 additions & 19 deletions pkg/sieve.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package pkg

import (
geometry "github.com/twpayne/go-geom"
"github.com/twpayne/go-geom/xy"
"log"
"math"

Expand All @@ -27,25 +29,28 @@ func sieveFeatures(preSieve chan Feature, postSieve chan Feature, resolution flo
preSieveCount++
switch feature.Geometry().(type) {
case geom.Polygon:
var p geom.Polygon
p = feature.Geometry().(geom.Polygon)
if p := polygonSieve(p, resolution); p != nil {
feature.UpdateGeometry(p)
p := feature.Geometry().(geom.Polygon)
sievedPolygon, isReduced := polygonSieve(p, resolution)
feature.UpdateGeometry(sievedPolygon)
feature.IsReduced(isReduced)
if !isReduced {
postSieveCount++
postSieve <- feature
}
postSieve <- feature
case geom.MultiPolygon:
var mp geom.MultiPolygon
mp = feature.Geometry().(geom.MultiPolygon)
if mp := multiPolygonSieve(mp, resolution); mp != nil {
feature.UpdateGeometry(mp)
multiPolygonCount++
mp := feature.Geometry().(geom.MultiPolygon)
mp, isReduced := multiPolygonSieve(mp, resolution)
feature.UpdateGeometry(mp)
feature.IsReduced(isReduced)
multiPolygonCount++
if !isReduced {
postSieveCount++
postSieve <- feature
}
postSieve <- feature
default:
postSieveCount++
nonPolygonCount++
feature.IsReduced(false)
postSieve <- feature
}
}
Expand All @@ -57,7 +62,7 @@ func sieveFeatures(preSieve chan Feature, postSieve chan Feature, resolution flo
if preSieveCount != nonPolygonCount {
log.Printf(" multipolygons: %d", multiPolygonCount)
}
log.Printf(" kept: %d", postSieveCount)
log.Printf(" not reduced: %d", postSieveCount)
}

// writeFeatures collects the processed features by the sieveFeatures and
Expand All @@ -69,19 +74,54 @@ func writeFeaturesToTarget(postSieve chan Feature, kill chan bool, target Target
kill <- true
}

// getMultiPolygonCentroid returns Point with the centroid value of a multiPolygon
func getMultiPolygonCentroid(mp geom.MultiPolygon) geom.Point {
var multiPolygonCoords [][][]geometry.Coord
for _, p := range mp {
multiPolygonCoords = append(multiPolygonCoords, getPolygonCoords(p))
}
if len(multiPolygonCoords) != 0 {
centroidCoord, err := xy.Centroid(geometry.NewMultiPolygon(geometry.XY).MustSetCoords(multiPolygonCoords))
if err != nil {
panic(err)
}
return [2]float64{centroidCoord[0], centroidCoord[1]}
} else {
return [2]float64{0, 0}
}
}

// getPolygonCentroid returns Point with the centroid value of a polygon
func getPolygonCentroid(p geom.Polygon) geom.Point {
polygonCoords := getPolygonCoords(p)
if polygonCoords != nil {
centroidCoord, err := xy.Centroid(geometry.NewPolygon(geometry.XY).MustSetCoords(polygonCoords))
if err != nil {
panic(err)
}
return [2]float64{centroidCoord[0], centroidCoord[1]}
} else {
return [2]float64{0, 0}
}
}

// multiPolygonSieve will split it self into the separated polygons that will be sieved before building a new MULTIPOLYGON
func multiPolygonSieve(mp geom.MultiPolygon, resolution float64) geom.MultiPolygon {
func multiPolygonSieve(mp geom.MultiPolygon, resolution float64) (geom.MultiPolygon, bool) {
var sievedMultiPolygon geom.MultiPolygon
var isReduced bool
for _, p := range mp {
if sievedPolygon := polygonSieve(p, resolution); sievedPolygon != nil {
if sievedPolygon, b := polygonSieve(p, resolution); b == false {
sievedMultiPolygon = append(sievedMultiPolygon, sievedPolygon)
} else {
isReduced = true
sievedMultiPolygon = append(sievedMultiPolygon, [][][2]float64{{getPolygonCentroid(p)}})
}
}
return sievedMultiPolygon
return sievedMultiPolygon, isReduced
}

// polygonSieve will sieve a given POLYGON
func polygonSieve(p geom.Polygon, resolution float64) geom.Polygon {
func polygonSieve(p geom.Polygon, resolution float64) (geom.Polygon, bool) {
minArea := resolution * resolution
if area(p) > minArea {
if len(p) > 1 {
Expand All @@ -92,11 +132,15 @@ func polygonSieve(p geom.Polygon, resolution float64) geom.Polygon {
sievedPolygon = append(sievedPolygon, interior)
}
}
return sievedPolygon
return sievedPolygon, false
}
return p
return p, false
}
if p == nil {
return nil, false
} else {
return [][][2]float64{{getPolygonCentroid(p)}}, true
}
return nil
}

// calculate the area of a polygon
Expand Down Expand Up @@ -145,3 +189,24 @@ func Sieve(source Source, target Target, resolution float64) {
}
close(kill)
}

func getPolygonCoords(p geom.Polygon) [][]geometry.Coord {
var multiXyCoordinates [][]geometry.Coord
if p == nil {
return nil
}
for _, polygon := range p {
var xyCoordinates []geometry.Coord
if len(polygon) != 0 {
for _, point := range polygon {
xyCoordinates = append(xyCoordinates, makeCoord(point))
}
multiXyCoordinates = append(multiXyCoordinates, xyCoordinates)
}
}
return multiXyCoordinates
}

func makeCoord(point [2]float64) geometry.Coord {
return geometry.Coord{point[0], point[1]}
}
Loading

0 comments on commit ab40288

Please # to comment.