[Qgis-user] multiple csv file import
Ujaval Gandhi
ujaval at spatialthoughts.com
Wed Nov 16 02:01:23 PST 2022
Another option is to use the tool 'Create Points Layer from Table' tool from
QGIS Processing Toolbox. This tool can read a CSV and create a point layer (i.e.
shapefile). First test it on a single file and if it works for your use case,
you can click the 'Run as a Batch Process' and run it on all files in your
folder.
---
Ujaval Gandhi
Spatial Thoughts
www.spatialthoughts.com [http://www.spatialthoughts.com]
[data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=3D]
On Wed, Nov 16, 2022 at 3:04 AM Salvatore Mellino via Qgis-user
<qgis-user at lists.osgeo.org> wrote:
> I found this on line :
>
>
>
>
> import glob, os
>
> # Define path to directory of your csv files
> path_to_csv = "C:/File Path/"
>
> # Set current directory to path of csv files
> os.chdir(path_to_csv)
> # Find each .csv file and load them as vector layers
> for fname in glob.glob("*.csv"):
> uri ="file:///"+path_to_csv + fname+"encoding=%s&delimiter=%s&xField=%s&yField=%s&crs=%s" % ("UTF-8",",", "Long", "Lat","epsg:4326")
> name=fname.replace('.csv', '')
> lyr = QgsVectorLayer(uri, name, 'delimitedtext')
> QgsProject.instance().addMapLayer(lyr)
>
>
>
>
> but it doesn’t work. I have csv files with lat long and value separated by space and without header
>
>
>
>
> > Il giorno 15 nov 2022, alle ore 21:22, Hugh Kelley <hghklly at gmail.com
> > [hghklly at gmail.com]> ha scritto:
>
> >
> > Awesome thanks very much. glad I asked, you learn something new every day.
> >
> >
> > On Tue, Nov 15, 2022 at 3:19 PM David Strip <qgis-user at stripfamily.net
> > [qgis-user at stripfamily.net]> wrote:
> >
> > > Starting with v2.1, ogr2ogr supports args X_POSSIBLE_NAMES,
> > > Y_POSSIBLE_NAMES which are strings with allowed wildcards (eg, Lon* ), or
> > > you can use field_1, field_2, etc to explicitly give the position of
> > > lat/lon.
> > > It's explained on the driver page.
> > > [https://gdal.org/drivers/vector/csv.html] This StackExchange
> > > [https://gis.stackexchange.com/a/276607/4449]post shows csv to shapefile
> > > conversion and included Windows command line syntax for looping over files
> > > in a directory.
> > >
> > > On 11/15/2022 12:58 PM, Hugh Kelley wrote:
> > >
> > > > David, this was my first thought when i saw this question as well.
> > > >
> > > >
> > > > however, I didn't look for very long but I haven't seen a way to tell
> > > > ogr2ogr to read columns in a csv as the lat/lon and write those as
> > > > points to the shapefile. I generally write a csv to postgres as a
> > > > non-spatial table and then process the lat lon columns with postgis.
> > > >
> > > >
> > > >
> > > > Are there arguments for ogr2ogr that can do this?
> >
> >
> >
> > --
> >
> > Hugh Kelley
>
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org [Qgis-user at lists.osgeo.org]
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> [https://lists.osgeo.org/mailman/listinfo/qgis-user]
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
> [https://lists.osgeo.org/mailman/listinfo/qgis-user]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20221116/c85e7203/attachment-0001.htm>
More information about the Qgis-user
mailing list