2

I'm trying to build an application that will resolve the corresponding "region" of a point. So basically if a lat-lng point is inside Polygon-A or Polygon-B.

I have all the files (I hope at least), a .shp, a .prj and two more binary files. I'm trying to do it in Go, I've found a library that is able to read the shp file (go-shp: https://github.com/jonas-p/go-shp ) but I'm not sure how to derive the coordinates.

Is it possible or am I missing something? Do I need to convert it in GeoJSON or something like that?

Sorry but I'm pretty noob about GIS!

EDIT:
Reading the Polygon object returned by the library the points associated are in the form of something like this:

[
    {984002.7992000002 4.6707144145e+06}
    {985067.0396999996 4.670245166999999e+06}
    {985239.5382000003 4.670172667400001e+06}
    ...
]

and I'm not sure on how to use it.

The .prj file contains these informations:

PROJCS[
    "WGS_1984_UTM_Zone_32N",
    GEOGCS[
        "GCS_WGS_1984",
        DATUM[
            "D_WGS_1984",
            SPHEROID["WGS_1984",6378137.0,298.257223563]
        ],
        PRIMEM["Greenwich",0.0],
        UNIT["Degree",0.0174532925199433]
    ],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["False_Easting",500000.0],
    PARAMETER["False_Northing",0.0],
    PARAMETER["Central_Meridian",9.0],
    PARAMETER["Scale_Factor",0.9996],
    PARAMETER["Latitude_Of_Origin",0.0],
    UNIT["Meter",1.0]
]
1
  • You'll need to read a shapefile to get the (projected) geometry, which you've already found a library for. Then you'll want to use a Proj4 implementation to do coordinate system transformations: github.com/pebbe/go-proj-4 Then you'll want a point-in-polygon algorithm: github.com/JamesMilnerUK/pip-go I've never used Go, but in Python this process is typically done with Fiona (reading shapefile), pyproj (projection management), and Shapely (geometry). Hope that helps. – alphabetasoup Feb 6 '17 at 21:53
3

As stated in the docs for go-shp (https://godoc.org/github.com/jonas-p/go-shp#Polygon), Polygon structure is similar to PolyLine (which is defined as https://godoc.org/github.com/jonas-p/go-shp#PolyLine).

You can iterate over the features of the shapefile similar to the example in the README.md of the github page and use the function Shape() to get the ShapeType as well as the object. Since your object would be Polygon (whose structure is similar to PolyLine), you should be able to derive the co-ordinates of the polygon by accessing the array Points defined in the structure.

8
  • Thanks! So I don't need any other files? The coordinates are inside the .shp file? – Enrichman Feb 6 '17 at 19:48
  • Yes, the coordinates are in the .shp file but you'll need the .dbf file too. The .shp file contains the geometry of the features and the .dbf file contains the attribute data. Both will be needed for using the go-shp library. – nash Feb 6 '17 at 20:00
  • Yep, I'm almost done. The processing works but I don't know how to use the points actually... I've edited the question adding the lines inside the .prj file, maybe they explain something. How can I match a standard lat-long (ie: 12.123N, 23.456E) within those points? Do I need to convert them somehow? – Enrichman Feb 6 '17 at 21:12
  • Along with the .dbf, .shp the other required file that makes up a shapefile is the .shx. The .prj file is optional but nice if you have it. Just make sure these files are all in the same directory before running any scripts against them. – artwork21 Feb 6 '17 at 21:19
  • @artwork21 Yes, I have also that one – Enrichman Feb 6 '17 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.