How can I rasterize the polygons of a Shapefile in Julia?

I’ll admit that I was disappointed when I started this thread and noticed that the Geo subforum had a grand total of just 7 threads since February 2017. So my expectations for getting help on a problem related to geospatial data were set very low. Even considering that, the level of engagement from the developers shown here is amazing. Maybe it’s just the “OMG OMG we actually have a USER!!” factor, but whatever the reason, thanks guys!

Done.

Maybe some progress: I uninstalled v5.4, installed GMT6dev and added GMT6\bin to my path. Now I get a different error when running ]test GMT or the Hello World example in the GMT docs:

6.0.0_r20419
ERROR: LoadError: GMT: Failure to open virtual file
Stacktrace:
 [1] error(::String) at .\error.jl:33
 [2] GMTJL_Set_Object(::Ptr{Nothing}, ::GMT.GMT_RESOURCE, ::Array{Float32,2}) at C:\Users\niclas\.julia\packages\GMT\SwD1H\src\gmt_main.jl:979
 [3] gmt(::String, ::Array{Float32,2}) at C:\Users\niclas\.julia\packages\GMT\SwD1H\src\gmt_main.jl:262
 [4] top-level scope at C:\Users\niclas\.julia\packages\GMT\SwD1H\test\runtests.jl:16
 [5] include at .\boot.jl:317 [inlined]
 [6] include_relative(::Module, ::String) at .\loading.jl:1038
 [7] include(::Module, ::String) at .\sysimg.jl:29
 [8] include(::String) at .\client.jl:388
 [9] top-level scope at none:0
in expression starting at C:\Users\niclas\.julia\packages\GMT\SwD1H\test\runtests.jl:13
ERROR: Package GMT errored during testing

And when I try the DCW example in your first post above I get an error from pscoast that suggests I download DCW manually and install it to “DIR_DCW, the shared dir, or the user dir”. Where do you suggest I put it?

Honestly, I wasn’t enamored of the ArchGDAL syntax you posted above, probably because it triggered some latent PTSD from asyncronous nested callback hell in Node.js. Or maybe I just want things like drivers and C-pointers to be abstracted away. But I understand this is work in progress! I’m just glad I can get something to work right now. If I need nicer call syntax I’ll just wrap your code in a function.

In addition to Python and R you should look at Matlab syntax for shapefiles, it’s pretty straightforward. You use shapeinfo() to read the metadata into a standard Matlab struct, shaperead() to extract vector data or vec2mtx() to rasterize.

1 Like