Tag Info

Hot answers tagged

6

Main problem is getting the area of the extent. I wrote a quick ogr function to do this def extentArea(extent): #Unpack extent tuple to coordinates minX, minY, maxX, maxY = extent #unpack the tuple #Create empty geometry and add vertices geom = ogr.Geometry(type = ogr.wkbLinearRing) geom.AddPoint_2D(minX,minY) ...


6

The following example shows how to integrate the built-in python method .upper() with the arcpy update cursor. This example first tests if a field is of type String then checks each row within that string for lowercase values. If there are lower case values, the row is updated with all upper case. import arcpy fc = r'C:\temp\test.gdb\yourFC' desc = ...


4

Python's split() returns a list object (an array), so if you use split("_") on "A_B_C_D" you get an array where you can access every Letter by its index. The underscore acts as an separation character in this case, and parsing character separated lists is one of the most common uses of the split() function fielda= field1.split("_")[0] fieldb= ...


4

I made a custom Shorten Polylines toolbox for you. I only tested it with about 5 lines, but it should do the same with tens of thousands. It works with ArcGIS 10.1+ It creates new, shortened polylines based on a specified distance or percentage. The value can be fixed or field based. The output contains a field called LineOID, which is the OID of the ...


4

ArcGIS has a tool to do just that called Bearing Distance To Line (Data Management). The syntax is as follows (from ESRI help): # Import system modules import arcpy from arcpy import env # Local variables input_table = r"c:\workspace\LOBtraffic.dbf" output_fc = r"c:\workspace\SOPA.gdb\lob_traf001" #BearingDistanceToLine ...


4

for rounding your convex angles, you can apply successively a negative then a positive buffer of the same radius. For the angles shown on your figure, you are thus applying the method on the blue polygons. the buffer tool in shapely is part of the shapely.geometry package


4

It is easiest with shapely: from shapely.geometry import box extents = [(-180.0, -90.0, 180.0, 83.624), (-124.731, 24.956, -66.97, 49.372), (-122.42, -37.818, 151.207, 52.516)] for i in extents: a = box(i[0],i[1],i[2],i[3]) print i, a.area (-180.0, -90.0, 180.0, 83.623999999999995) 62504.64 (-124.73099999999999, 24.956, -66.969999999999999, ...


3

Below is a ToolValidator class (in its entirety so it will make sense) where I needed not only for input datasets to have a spatial reference defined, BUT the datum could only be either WGS84 or NAD83. If validation failed, they got little messages informing them of the issues. class ToolValidator: """Class for validating a tool's parameter values and ...


3

If you want to do this "right" (taking into account the fact that latitude and longitude are angular units, and using an ellipsoid as a model of the earth's shape), you can try using the geographiclib library, which is a Python version of Charles Karney's Algorithms for geodesics. See also the Wikipedia page Geodesics on an ellipsoid for a look into some of ...


3

The following explains (1.) how to construct technically a polygon from points and (2.) different methods to construct a polygon from points. 1. Tool to create a polygon from point coordinates I would use the GDAL Python bindings to do that. To give you a starting point have a look at the following script: from osgeo import ogr # you have a list of ...


3

I think you're getting the error because the fieldnames list still contains the field LABEL, but you said you're not adding it to the output_fc. for field in fields: fieldnames.append(field.name) Right here you're getting all the field names. If you do a print statement above this line: cursor = arcpy.da.InsertCursor(output_fc, fieldnames) I ...


3

Try polygon.buffer(10, join_style=1).buffer(-10.0, join_style=1) A dilation, rounded (join_style=1), followed by an erosion, rounded. There's a diagram of a similar procedure at http://toblerity.org/shapely/manual.html#object.buffer.


3

I have only tested this very briefly (and with a limited variety of data), but this script demonstrates one way this might be accomplished: import arcpy import csv import os import codecs import cStringIO def batch_convert_dbf_to_csv(input_dir, output_dir, rename_func=None): """Converts shapefiles and standalone DBF tables within the input directory ...


3

If you look for a full arcpy solution (without dbf) you can use import glob glob.glob('S:\\output_tables\\*.dbf') for listing you tables, then arcpy.ListFields() for the field names and outname = os.path.basename(inputtable)[3:-4] + ".csv" to create your output names and finally arcpy.da.SearchCursor() to get a Python iterable that you can ...


3

You need to have admin privileges on the box. For Windows 7: Click on the start menu. Right click on "Computer" Click "Properties" Click "Advanced system settings on the left menu bar You may have to type in a password here. The second box is titled "system variables" on of them is "PATH" Select path, click edit. Go to the end of the PATH variable ...


3

You can get it this way: row.GetValue("your_shape_field_name").GetPart().z And here you can get more information and a complete example from the ArcGIS Desktop Help.


3

There appears to be a solution on your duplicate post on the Esri forums: You just need to delete this part (first three lines of the script): Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> I think the author of this tool meant to ...


2

Given a point (excavation site), you can use an SQL-language function to project lines out in the cardinal directions, to a specified radius: CREATE OR REPLACE FUNCTION cardinal_lines (g geometry, r float) RETURNS TABLE (dir varchar(2), geom geometry) AS $$ SELECT 'NE'::varchar(2), ST_MakeLine(g, ST_SetSRID(ST_MakePoint(ST_X(g) + sqrt(r/2), ST_Y(g) + ...


2

As you state your lines are straight you could get a handle on each polyline and get the FROM end of the polyline as a point. Then query the polyline to create the TO end point. Combine these 2 points to create your reduced polyline. You could either overwrite the existing geometry or write the new polyline off to a new featureclass with the polyline ID (So ...


2

Individual bands can be accessed by calling GetRasterBand(4) from your datasource. You could then write your band as array into a newly created copy. For instance like this: driver = gdal.GetDriverByName("....") tDs = driver.Create(output, cols, rows, 1, gdal.GDT_Float32) ds_in = gdal.Open('in.tif') array = ds_in.GetRasterBand(4).ReadAsArray() # get ...


2

Just been looking at this thread and followed the link to the other thread which showed Numpy being used. I've personally never used this approach before so I started reading the help file about it and I think this can all be done in 5 lines! The dataset I tested this on was a polyline layer representing the rivers of the Amazon. So my code is as: InFc = ...


2

It doesn't look like your code properly saves/closes the dataset. To do this, add this to the end: dst_ds = None # save, close Also, although it looks like you want to use -999 for NODATA, this needs to be set to the resulting band. If you want to learn more about raster processing with Python, check out rasterio.


1

The length of the string should not be a problem in your case. For Python the maximum string length is more than 2 Go in 32-bit (see here). As mentioned in the comment, each individual path in the concatenated string is limited in the Windows API (with some exceptions like the use of "\?\" for very long paths). The maximum length for a path is defined ...


1

You cannot apply this particular example without understanding the JSON format: your external file "file.json" is not an .json file A correct format would be (without var states = [:) { "type": "Feature", "properties": {"party": "Republican"}, "geometry": { "type": "Polygon", "coordinates": [ [ [ -84.32281494140625, ...


1

I don't have the full picture (where does z1 come from and is it valid ? Is your shapefile a 3D shapefile ?), but for a start the use of two cursors does not seem to be necessary. while rowLine: #... feat = rowsPoint.NewRow() ptObj = gp.CreateObject('Point') ptObj.x = x1 ptObj.y = y1 ptObj.z = z1 feat.Shape = ptObj ...


1

Go to the Python GDAL/OGR Cookbook 1.0 documentation and you'll have the answers to all your questions: from osgeo import ogr driver = ogr.GetDriverByName('ESRI Shapefile') shape = driver.Open('my.shp') layer= shape.GetLayer() # the crs crs = layer.GetSpatialRef() and you can also create a projection file if the shapefile does not ...


1

The closest thing we have in Python to a standard built-in Polygon is defined in "A Python Protocol for Geospatial Data": https://gist.github.com/sgillies/2217756. The most straightforward way to get a Python polygon is to do this: # you have a list of points listPoint = [[13.415449261665342, 52.502674590782519],[13.416039347648621, ...


1

Here's a quick example: fc = "whatever" fields = ("Name", "Addy", "Stuff") with arcpy.da.UpdateCursor(fc, fields) as cursor: for row in cursor: row[0] = row[0].upper() row[1] = row[1].upper() row[2] = row[2].upper() cursor.updateRow(row) And here's the ArcGIS manual for the da.UpdateCursor


1

http://www.qgis.org/en/docs/pyqgis_developer_cookbook/composer.html has a simple Python example. http://spatialgalaxy.net/2012/01/27/qgis-running-scripts-in-the-python-console/ has a more detailed example.


1

This is a bug in 2.2 with the canvas and it's redraw event. The redraw event is called when the widget is first shown and it kicks off a timer which stops the canvas from painting. The workaround is as simple as calling: canvas.refresh() canvas.repaint() The first time the widget is shown.



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