evetion/GeoDataFrames.jl

Geometry column not showing the points explicitly in the README example and MERGING issue.

martinmestre opened this issue · 7 comments

Hi @evetion:
I have run the example commands in the README file from a Jupyter notebook that accepts Julia.
When I run:
df = GDF.read("test_points.shp")
I obtain a similar table to the one in the example but with the following differences:
The geometry is in the first column and the points do not appear explicitly but only says:
Geometry: wkbPoint

What can be the cause of the difference ?

The other questions is if I can use GeoDataFrames to merge a shapefile with a data frame when both
objects have a column in common. I want to preserve all the shapefile geometric structure.

Thank you very much,
Martín

visr commented

The geometry is in the first column and the points do not appear explicitly but only says:
Geometry: wkbPoint

This is due to changes in ArchGDAL since the readme what written. The order of the columns has no meaning and the geometry is only a matter of the show method I believe, not the actual content. Would be great if you could update the readme to what it looks like now though, since it would be less confusing.

The other questions is if I can use GeoDataFrames to merge a shapefile with a data frame when both
objects have a column in common. I want to preserve all the shapefile geometric structure.

See also my link to the DataFrames join method in JuliaGeo/Shapefile.jl#56 (comment). This package directly returns a DataFrame, so you can use this directly. The geometries will stay intact.

Thank you very much Martin @visr !
Ok, I will try to update the README file. Should I use the git command for that?

Regarding the other problem, this is what I want to do (GDF=GeoDataFrames):

graph_file="input.shp"
state_data = GDF.read(graph_file)
assignment = DataFrame(CSV.File(assignment_file))
graph_data = outerjoin(state_data,assignment, on = "GEOID20")
graph = BaseGraph(graph_data, population_col)

But the code gives error when reading the input file:

LoadError: MethodError: Cannot convert an object of type
ArchGDAL.IGeometry{wkbMultiPolygon} to an object of type
ArchGDAL.IGeometry{wkbPolygon}
Closest candidates are:
convert(::Type{var"#s404"} where var"#s404"<:ArchGDAL.AbstractGeometry, ::GeoFormatTypes.AbstractWellKnownText) at /home/mmestre/.julia/packages/ArchGDAL/erkjx/src/convert.jl:36
convert(::Type{var"#s404"} where var"#s404"<:ArchGDAL.AbstractGeometry, ::GeoFormatTypes.WellKnownBinary) at /home/mmestre/.julia/packages/ArchGDAL/erkjx/src/convert.jl:42
convert(::Type{var"#s404"} where var"#s404"<:ArchGDAL.AbstractGeometry, ::GeoFormatTypes.GeoJSON) at /home/mmestre/.julia/packages/ArchGDAL/erkjx/src/convert.jl:45

Do you have any clue of how to solve this problem ?
Best regards,
Martín

visr commented

Nice, thanks! You could use git, but for small changes I often find it more convenient to click the edit (pencil) button on github; https://github.com/evetion/GeoDataFrames.jl/edit/master/README.md.

Your issues actually looks like this one that came up recently on the ArchGDAL repository: yeesian/ArchGDAL.jl#223

Until that issue is fixed, perhaps you could save your data as GeoPackage and use that instead, since the issue is limited to shapefiles.

Thanks @visr !
Could you tell me which changes should be done to the following lines in order to save data to GeoPackage (I do not know how and when should that be done):

graph_file="input.shp"
state_data = GDF.read(graph_file)
assignment = DataFrame(CSV.File(assignment_file))
graph_data = outerjoin(state_data,assignment, on = "GEOID20")
graph = BaseGraph(graph_data, population_col)

visr commented

I think this should work:

df = GDF.read("input.shp")
GDF.write("input.gpkg", df)
state_data = GDF.read("input.gpkg")

It's a good idea to put 3 backticks around your code to make it easier to read by the way. If you write julia after your first 3 backticks it will even apply syntax highlighting.

```julia

Thanks @visr,

It seems the problem starts from the begining when reading the file

df = GDF.read("input.shp")

because it gives:

LoadError: MethodError: Cannot `convert` an object of type 
  ArchGDAL.IGeometry{wkbMultiPolygon} to an object of type 
  ArchGDAL.IGeometry{wkbPolygon}

Is there any solution for this?

I have tried to read directly with

state_data=ArchGDAL.read(graph_file)

It works ok for reading, but afterwards I cannot use the command:

graph_data = outerjoin(state_data,assignment, on = "GEOID20")

because it gives:

LoadError: MethodError: no method matching outerjoin(::ArchGDAL.IDataset, ::DataFrame; on="GEOID20")
Closest candidates are:
  outerjoin(::AbstractDataFrame, ::AbstractDataFrame; on, makeunique, source, indicator, validate, renamecols, matchmissing) at /home/mmestre/.julia/packages/DataFrames/pVFzb/src/join/composer.jl:1026
  outerjoin(::AbstractDataFrame, ::AbstractDataFrame, ::AbstractDataFrame...; on, makeunique, validate, matchmissin

Thank you very much,
Martín

visr commented

Ah sorry I missed that it failed on GDF.read. Another way you can convert to a GeoPackage is using the GDAL command line tools, see for instance the last example here: https://github.com/JuliaGeo/GDAL.jl#using-the-gdal-and-ogr-utilities