Hot answers tagged

55

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 ...


28

Here's a simple script that uses the OGR python bindings: import ogr,csv,sys shpfile=r'C:\Temp\test.shp' #sys.argv[1] csvfile=r'C:\Temp\test.csv' #sys.argv[2] #Open files csvfile=open(csvfile,'wb') ds=ogr.Open(shpfile) lyr=ds.GetLayer() #Get field names dfn=lyr.GetLayerDefn() nfields=dfn.GetFieldCount() fields=[] for i in range(nfields): fields....


28

It doesn't work because you haven't called the Xlrd modules to read the Excel spreadsheet. Implement it something like this: import xlrd workbook = xlrd.open_workbook('my_workbook.xls') worksheet = workbook.sheet_by_name('Sheet1') This will allow you to read an XLS file with Python. However, ArcPy will read XLS without Xlrd. You can consider the Excel ...


26

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.


18

This works for me, using the arcpy.da.Walk function at ArcGIS 10.1 SP1: import arcpy, csv, os workspace = r"c:\GISData" output = r"C:\temp\test.csv" with open(output, 'wb') as csvfile: csvwriter = csv.writer(csvfile) for dirpath, dirnames, filenames in arcpy.da.Walk(workspace): for filename in filenames: desc = arcpy.Describe(...


16

Introduction Because this issue (of discrepancies in standard deviations, variances, or other statistical summaries) comes up periodically, especially when a thoughtful and careful GIS analyst checks their work, I thought it would be good to share the "forensic analysis" of the discrepancy so that readers can carry out similar checks in their own ...


16

Given a list of geographic coordinate pairs, you can implement the Haversine formula directly in Excel. The simplest way to use this (or a more accurate, but I think it's not your case) formula consists into press Alt+F11 to open the VBA Editor, click Insert --> Module and then (copy and) paste e.g. the code kindly suggested by blah238. Public Function ...


14

If you are going to ArcMap 10.1 you could create a python add-in. The add-in gives you access to an "on open" function that will run code when you open the mxd. The help here explains how to create one and has a sample that adds a base layer to the mxd when opening.


13

I would do the following things to make life easier: Before you do this, make a backup of your shapefile. In your shapefile, go to the layer properties / fields and turn on edit mode. select all Field except the ID field Delete all fields except the ID Field add your csv file as a layer in QGIS (Main menu/Layer/Add Layer/ Add delimited text layer) (...


13

You can often make a WKT (Well Known Text) column in Excel without too much fiddling, which effectively creates a spatial definition for points, lines or polygons within a single field. What you want to do is create a WKT string, in the format: POLYGON((X1 Y1, X2 Y2, X3 Y3, X4 Y4, X1 Y1)) You can create new columns in Excel with the below formulas. The ...


12

You will want to join the excel file to the shapefile. You will join them on a common attribute and the result will be a joined layer where each record hold the attributes of both the shapefile and the excel file. Ok first you load your excel file and your vector later into the layers. I used some test data I made but your setup should look similar to ...


11

The GEOCONTEXT-PROFILER will create an elevation profile just like Google Earth and you can import a KML and export a CSV. It should give you the same results as Google Earth. This is the license restriction page that the tool links to.


11

If you already have your data in excel make sure of the following a)Data must be in decimal degrees b)First row of the file has the name of the field (this is just an example) then you have to save the file as a csv comma delimited (not msdos or mac). After opening Qgis you have to look for the "add delimited text layer plugin (a blue postit with commas ...


11

Extracting coordinates of start/end vertices (not all line vertices) from lines is a nice use case for new functionality in QGIS v.2.8, namely, the function editor. This is the workflow: Load your line layer to QGIS and activate it. Open the field calculator and go to tab Function Editor. Click on New file, write vertices as the new file name, and click on ...


11

Save your excel file as CSV file go to Add Vector Layer in QGIS and navigate to your CSV file and load it In the print composer, go to Add attribute table, as you can see below: Select the Source from Layer Feature from the window in the right,as shown below: You can change the font and formats based on your needs, and here is final output: UPDATE In ...


10

When you use Python, you must use the correct modules to do what you want. To find all files in a directory with extension shp, for example, there are much simpler solutions that was presented without the break, which is awful...(as the solution presented by Nathan W, but there are many, many others, just search on Internet) Some examples with relevant ...


10

All of the trigonometric functions you need are in the math module. I presume you'll want atan2() which is the equivalent of atan(y/x). For the mod function, you'll need to use the percent symbol. Each function also has a simplified version (a) since you are calculating some constants. They're identical functions but will be faster. Parser: Python ...


10

You could use the Group Stats plugin from Plugins > Manage and Install Plugins. This calculates various data statistics for your attributes such as finding the minimum value in a group. I made an example of attributes from the data you gave: Then from the Group Stats interface, select and drag the toid field from the list into the Rows window; and repeat ...


10

Just to add another method, you can set up a Project macro which when loaded: Automatically joins your shapefile to your csv Updates the IP1 and IP2 fields Removes the joined fields leaving only the shapefile's fields (i.e. no dulplicates) First, create a project if you haven't already done so and then go to the toolbar: Project > Project Properties... > ...


9

Like whuber says, you have to write out the headers explicitly. I loaded up dbfpy and xlwt in a virtualenv and ran this: from xlwt import Workbook, easyxf import dbfpy.dbf from time import time def test1(): dbf = dbfpy.dbf.Dbf("pipelines.dbf", readOnly = True) header_style = easyxf('font: name Arial, bold True, height 200;') book = Workbook() ...


9

If you open the attribute table, open an empty excel spreadsheet, Select all or some of the records in the attribute table. to select all the button in upper left gives this pulldown to accomplish that. right click on the left edge (on a box). copy selected. Switch to the spreadsheet. right click in the upper left cell (just one cell) ctrl+V (paste)....


9

No idea what happened with the first three lines but the other lines are coordinates in UTM zone 28N. data_lat is X, data_lon is Y. I noticed that simply plotting each pair as X and Y points looked very similar, so I gave it a try on http://projfinder.com with success.


8

If you convert your shapefile to spatialite, you should be able to do the following: 1) Experiment with SQL to test the output: ex. SELECT col1, col2, col3, AsKml(geometry_column) FROM tab 2) Once you are satisfied with the result, you can export it to CSV format: https://stackoverflow.com/questions/5776660/export-from-sqlite-to-csv-using-shell-script ...


8

Assuming the columns appear in time order, the first row (for example) indicates that total construction through each period went 0, 0+45 = 45, 45+135 = 180, 180+405 = 585, 585+1010 = 1595, ..., 2230+0 = 2230. Construction was halfway through at 2230/2 = 1115. This occurred during period 4, because at the end of period 3 the total was 585, at the end of ...


8

the attributes of a shapefile are stored in an extra dbase-file. for example: mypolygons.shp contains geometries, mypolygons.dbf contains attributes. via an id the attributes are connected to the polygons. so just simple load your dbf file into capable software (e.g libreoffice) , edit attributes and your done


8

If you don't need some kind of routine or script, here is the simple procedere using QGis (Master 1.9, but 1.8 should also work). Add your shapefile as vector layer in QGIS Add your table (can be .csv or .xls files) to QGis in the same way -> Add Vector Layer Both, table and layer should now be visible in the layer table of contents. Now make a simple Join ...


8

Threading doesn't work with most UI manipulation in Windows as UI elements have thread affinity, which is probably why the map view is failing to refresh. I've got a Python project that does this in ArcGIS without threading on Github. It uses the Win32 event loop in the main thread to do timed calls in an add-in extension. You can also use it independently ...


8

I had the same problem (Arcmap would not import my csv file with headers, instead it would show Field1, Field2, Field3 etc). When I examined the file headers in Excel, I found...decimals numbers, spaces, percent signs etc. After replacing all of that with underscores or text, I had no problems. I dragged the .csv file into arcmap, opened the attribute ...


8

There's also the MMQGIS plugin which, when downloaded and installed from the toolbar (Plugins > Manage and Install Plugins...), has the tool: Attributes Export to CSV File


8

QGIS, or more specifically OGR, has two different drivers for XLS and XLSX (see http://www.gdal.org/ogr_formats.html) XLSX can be edited, XLS can not. Try converting your data to XLSX and you should be able to edit the dataset in QGIS afterwards.


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