Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document better how to write vector data #400

Open
maxfreu opened this issue Nov 19, 2023 · 1 comment
Open

Document better how to write vector data #400

maxfreu opened this issue Nov 19, 2023 · 1 comment

Comments

@maxfreu
Copy link
Contributor

maxfreu commented Nov 19, 2023

Hi! This is half an issue and half a reminder to myself that I / we should improve the documentation on how to write vector data. Just struggled to come up with code to write a dumb file containing points. Had to read the tests to do it and even then it didn't work without tweaking. Here's what I came up with for reference:

function write_result_sqlite(filename, points)
    AG.create(filename; driver=AG.getdriver("SQLite")) do ds
        AG.createlayer(name = "geom",
                       dataset = ds,
                       geom = AG.wkbPoint,
                       spatialref = AG.importEPSG(25832)) do layer
            AG.addfielddefn!(layer, "point_id", AG.OFTInteger)
            id_idx = AG.findfieldindex(AG.layerdefn(layer), "point_id")
            i = 0
            for chunk in Iterators.partition(points, 20000)
                GDAL.ogr_l_starttransaction(layer)
                for pt in chunk
                    AG.addfeature(layer) do feature
                        AG.setfid!(feature, i)
                        AG.setfield!(feature, id_idx, i)
                        AG.setgeom!(feature, 0, AG.createpoint(pt...))
                        return nothing
                    end
                    i += 1 
                end
                GDAL.ogr_l_committransaction(layer)
            end
        end
    end
    return nothing
end

Speed is good, but it's a bit clunky. A higher level API for this kind of tasks would be really nice as well.

@yeesian
Copy link
Owner

yeesian commented Nov 24, 2023

This was something I ran into too, and fully agree with, thank you for writing this up and providing the code snippet for it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants