Hot answers tagged

92

Convert the DataFrame's content (e.g. Lat and Lon columns) into appropriate Shapely geometries first and then use them together with the original DataFrame to create a GeoDataFrame. from geopandas import GeoDataFrame from shapely.geometry import Point geometry = [Point(xy) for xy in zip(df.Lon, df.Lat)] df = df.drop(['Lon', 'Lat'], axis=1) gdf = ...


63

UPDATE 13.10.2016: Right click on the layer in the Table of Contents (aka. legend or layer tree) and open the Save As... dialog. Once there, click on the Format option list and choose MS Office Open XML spreadsheet [XLSX]. Note that you also have an option for Libre Office files: Open Document spreadsheet [ODS]. I'm using QGIS v.2.14.4 PREVIOUS ...


39

I once had the same question. The answer is that you put a file in the same folder with the ending csvt. For example your file name is xyzdata.csv you add the file xyzdata.csvt This one you can edit with editor for example. And in it you set the data type like this. "Integer","String","Integer","Integer","String","Real" Integer is now the variable for the ...


28

To get a csv file of the attribute table, rightclick on the layer in the legend, select Save As ..., and change the file format from shapefile to CSV. You might need to change the separator from comma to semicolon in a text editor if Excel does not like the default separator.


26

Update 201912: The official documentation at https://geopandas.readthedocs.io/en/latest/gallery/create_geopandas_from_pandas.html does it succinctly using geopandas.points_from_xy like so: gdf = geopandas.GeoDataFrame( df, geometry=geopandas.points_from_xy(x=df.Longitude, y=df.Latitude) ) You can also set a crs or z (e.g. elevation) value if you want. ...


24

The ogr2ogr utility supports a limited sql syntax. You can join your CSV to the shapefile using something like the following: ogr2ogr -sql "select inshape.*, joincsv.* from inshape left join 'joincsv.csv'.joincsv on inshape.GISJOIN = joincsv.GISJOIN" shape_join.shp inshape.shp


21

I would go the complicated way: Two Tables in a 1:n relation one table with the point location of the graves another table with the Grave-ID and person data You can build a relation between the two tables so that selecting a grave will select all person records in the person-table. The idea of having tables with fields like Person1, Person2... is ...


19

You mention that you computed a list of values in a Python script, so the easiest way to dump that to a csv would be to use the csv module! import csv res = [x, y, z, ....] csvfile = "<path to output csv or txt>" #Assuming res is a flat list with open(csvfile, "w") as output: writer = csv.writer(output, lineterminator='\n') for val in res: ...


18

My quick fix is to create the first row all with dummy values, and then delete this row/record after bringing into in ArcGIS. This first row contains representative values or often wildly different values (e.g. alphabetic characters even if the column contains numbers that I want to be text data type) and with the largest number of characters needed for ...


17

I had to solve the same problem today, so here is my answer, which gives a complete solution. I have a lineWKT.csv file stored in F:\Data\ folder, with the data like this: id,gm 0,"LINESTRING (30 10 0, 10 30 0, 40 40 5)" I have a test.vrt file like this: <OGRVRTDataSource> <OGRVRTLayer name="lineWKT"> <SrcDataSource>F:\Data\...


17

I was able to export to CSV, using other than a comma, by separating the layer creation options in the Save As.. dialog with linebreaks. Neither comma, nor space-separating them (even when they were in quotes) worked, but the linebreaks did the trick. To emphasize.. THIS APPROACH WORKED (linebreak-separated): GEOMETRY=AS_WKT SEPARATOR=SEMICOLON ...


16

Two methods are described in other answers here: Save as CSV and in OGR Creation Options/Layers type "GEOMETRY=AS_XY": Getting list of coordinates for points in layer using QGIS? Create two calculated fields having the coordinates, then save as CSV: How do I calculate the latitude and longitude of points using QGIS?


16

You can do this using GDAL, it directly supports XYZ format. It doesn't matter if your coordinates are UTM, gdal_translate will output in the same coordinate system. So to convert to GeoTIFF is as simple as: gdal_translate test.xyz test.tif Look at the GeoTIFF doc for output options (such as compression) and the gdal_translate doc for more usage info. In ...


15

There are 2 immediate options that would best get you where you are trying to go. Your first, and probably easiest option, would be to download Quantum GIS, using the OSGeo4W Installer. Once you have installed that program, follow this tutorial, which covers Importing a .csv file to QGIS. Once you have imported the file, simply right click on the layer in ...


15

Rather than messing with the input file, trying to get everything picture perfect, just use the field calculator to convert the text to a number / real. See the examples below:


15

If you're looking to reproject csv files from the Python Console in QGIS then you could use the following script. All you would need to change are the three paths which are mentioned in the comments. Essentially, the script imports your csv files into QGIS as shapefiles (assuming your geometric fields are named X and Y). It then uses the qgis:reprojectlayer ...


14

I see 2 solutions: 1st you could create 2 attributes to store your lon/lat: select your layer toggle to edit mode open the attribute table open the attribute calculator (ctrl+i) name your column, choose the predefined geometry function $x, $y (in that dialog) second solution (works for all gemetry types) select your shp layer save as ... choose txt ...


14

The pyshp module is a bit tricky to get the hang of, but really useful once you get it going. I've written a script that reads in a csv of the example data and writes out a shapefile with the data stored as attributes of the correct datatypes. The pyshp/xbase datatyping has always been tricky for me until I found this user guide for the xbase format and as a ...


14

I have simplified your code and corrected the error by using the da module introduced in 10.1. It greatly streamlines the reading of data using cursors, and used in conjunction with the with command this code should be more stable than if it used the the older method of file access. It works by making a list of all the fields and then removing the fields ...


12

Yet another option, this is more of a theory and programmatic one, using arcpy. A polygon can consist not only of a single outer ring with a single inner donut hole -- they can be nested to an arbitrary number of levels. Consider the following: Difference between outer and inner rings http://edndoc.esri.com/arcobjects/8.3/componenthelp/esricore/.%...


12

Simply select the features on the map and use copy-paste (Ctrl + C , Ctrl + V) to copy the data into a text editor or Excel.


12

Instead of loading the .csv using Add vector layer, use the Delimited Text layer tool. It will try to detect the most fitting data type for each column. For more details see the QGIS user guide.


12

in case of csv, it probably would be easier to read it with pandas and then convert it to geopandas Dataframe import pandas as pd import geopandas as gp from shapely.geometry import Point stations = pd.read_csv('../data/stations.csv') stations['geometry'] = stations.apply(lambda z: Point(z.X, z.Y), axis=1) stations = gp.GeoDataFrame(stations)


12

Look at the samples on the specification site. You'll need to write a script in the language of your choice that will get you from [ {"date":"2014-09-25","time":"20:49:09","lat":"53.269","lon":"6.935","depth":"3.0","place":"Meedhuizen","mag":"1.5","type":"GH","last":"True"}, {"date":"2014-09-24","time":"23:49:36","lat":"53.351","lon":"6.693","depth":"3.0","...


12

According to the ogr2ogr csv documentation and also this answer, you need to specify which fields contain the geometry in a VRT file: <OGRVRTDataSource> <OGRVRTLayer name="test"> <SrcDataSource>test.csv</SrcDataSource> <GeometryType>wkbPoint</GeometryType> <LayerSRS>WGS84</LayerSRS> ...


12

You don't want to export csv, you should Save as... the shapefile which you joined the csv to. If you export csv table (which was not loaded with points geometry), there won't be any geometry and thus no shapefile. So it should go like this: drag and drop shapefile and csv into QGIS Double click on shapefile in layers list, switch to joins tab join csv to ...


12

You are putting the x and y coordinates in wrong order. -8.183973 is latitude (Y) and 111.845623 is longitude (X). You need to adjust the column of X and Y to be Y and X, respectively. The coordinates are in geographic, which means using WGS84 is suitable for the given coordinates. Here is an image showing the correct location in Google Earth:


12

Assuming you don't have a unique id field, you can use rule based symbols with the following filter $id % 10 = 1 The % sign is equivalent to remainder, so any row that divides by 10 with a remainder, i.e, every 10th row will remain while the others will be filtered out of the result.


11

The problem most likely is that all CSV columns have been imported as text fields. Text cannot be used for graduated styles. To fix this, you need a .csvt file for your CSV which specifies the data type of CSV columns explicitly. Basically, a .csvt file is a text file with only one line, e.g. "Integer","Real","String" For a CSV file with three columns. ...


Only top voted, non community-wiki answers of a minimum length are eligible