I do not understand this error: MethodError: no method matching iterate(::DataFrame)

Hi

I want to know what a function is doing.
The function can be found here:
[https://nbviewer.jupyter.org/github/JuliaX/iap2014/blob/master/GeoData.ipynb]

I have a dataframe which have columns with type “Shapefile”. So I guess it is not easy to share it here. But it looks like this:

image

THESE ARE THE LIBRARIES BEING USED

using Shapefile
using DataFrames
using Colors
using Compose
using Gadfly

THIS IS THE FUNCTION IN CODE

# Going from one kind of polygon to another
ESRI2Compose(poly::Shapefile.Polygon) = Compose.FormTree(Compose.Polygon([Compose.Point(point.x,point.y) for point in poly.points]))

THIS IS MY ATTEMPT

for row in df_x
    c = compose(c,compose(canvas(template),ESRI2Compose(row["x1"][1]),
    linewidth(0.05mm),stroke(color),fill(nothing)))
end

The goal is to apply that function to column “x1”

1 Like

When iterating over rows you should use for row in eachrow(df_x)

1 Like

Now I get this error:

image

Is it possible to use ONLY the ESRI2Compose function?
Something like this:

for row in eachrow(df_x)
    c = ESRI2Compose(row["x1"][1])
end

But I get this error:

Your example is not an MWE (see PSA: make it easier to help you), but it looks like you’re calling compose(c, ...) in your loop without first defining c.

It might be useful to have a look at the Julia language docs and maybe the documentation for the packages you’re using to get the hang of the basic usage, as step-by-step debugging via Discourse might be pretty time consuming…

2 Likes

But I cannot give a dataframe with type “Shapefile”

Not sure I understand - do you mean in terms of an MWE? There are many shapefiles available freely online, or you could equally just create a shapefile object manually in an MWE.

1 Like

Well, if I write the dataframe i get a “string” type instead of a “shapefile”

df_mwe = DataFrame(MBR=["Rect(-80.1133, 43.5557, -79.9648, 43.7129)"])

Currently none of the errors you encountered were related to actual shapefiles, so any DataFrame would have worked as an MWE. If you absolutely need a shapefile for the MWE you could either read it in from a publicly available URL or construct one using the constructor in the relevant package (I don’t work with shapefiles so wouldn’t know what this is, but above you are getting a String because "a" constructs a String, you would probably need something like ShapeFile(-80.1133, 43.5557, -79.9648, 43.7129) but the form of the constructor will depend on the package you’re using)

1 Like

I thought you needed me to give a shapefile for the MWE. I already have my shapefile in a dataframe.
Anyways I am currently using VegaLite. So I converted my shapefile to a topojson. The conversation is here: https://discourse.julialang.org/t/how-to-make-vegalite-read-my-topojson-file/34546/10