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 = ...
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
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 is now the variable for the ...
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.
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.
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
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 ...
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!
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:
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 ...
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:
0,"LINESTRING (30 10 0, 10 30 0, 40 40 5)"
I have a test.vrt file like this:
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):
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?
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 ...
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
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 ...
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 ...
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 ...
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 ...
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/.%...
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)
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
According to the ogr2ogr csv documentation and also this answer, you need to specify which fields contain the geometry in a VRT file:
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 ...
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:
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.
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.
For a CSV file with three columns. ...