Tag Info

New answers tagged

2

You have the path wrong for the line that reads: arcpy.mapping.MapDocument(r"C:\Project\\" + mxd) you have made the path a raw string, so the double backslash is wrong and making it fail, it should either be: arcpy.mapping.MapDocument(r"C:\Project\" + mxd) or: arcpy.mapping.MapDocument("C:\\Project\\" + mxd)


1

There is a ready-made tool called ET Spatial's "GeoTools". Where there is a tool called "ET Miscellaneous". In this tool there are two types of way to split polygons viz. By Percentage and By Area ( several units e.g sq m, hectares etc.). This tool splits polygons from any of the four side i.e NESW as the pictures shows. I used "up to down" i.e North to ...


0

QgsVectorLayer() approach is true. Here is the code which can read field names of a specific feature class in ESRI .GDB: from qgis.core import * QgsApplication.setPrefixPath("D:/OSGeo4W64/apps/qgis", True) QgsApplication.initQgis() layer = QgsVectorLayer("D:/pycharm/turkiye_db.gdb|layername=tr_il", "provinces", "ogr") fields = layer.pendingFields() ...


1

I took the reverse approach to finding peaks, I found the peak pixels first, and am now trying to select those exceeding a certain prominence (as described on peakbagger.com, they appear to manually inspect topos to get their peaks). A solution for finding the single pixel peaks is to use r.terraflow, followed by r.mapcalc looking for the minimum: Flow ...


2

This code worked for me. I modified a near point distance tool I wrote last year. To find max distance, just change the dist_type parameter from min to max: import arcpy, os, sys, traceback, math from os import path as p from datetime import datetime as d arcpy.env.overwriteOutput = True def Message(msg): print str(msg) arcpy.AddMessage(msg) def ...


1

The only way i know to remove symbology definitions whilst keeping all the required ones AND keeping the current symbology is manually in ArcMap. In case this is of help here are the instructions: Right click on layer in ArcMap and go to properties Select the symbology tab Right click the unwanted definition ('Extreme' in this case) and delete. This ...


0

Thanks to ndawson for his advice; direction in the right direction: Had to implement a test QObject to fufill the parent-child relations... # CSV attribute editor toolbox layer population(s) self.projCombo = QComboBox(self.iface.mainWindow()) self.projCombo.addItem('example slot') self.projCombo.addItem('another example slot') ...


3

If you have access to an ArcInfo license, you could use the Point Distance tool, which: Determines the distances from input point features to all points in the near features.... The tool creates a table with distances between two sets of points. if the default search radius is used, distances from all input points to all near points are calculated. ...


2

Your problem is with self.ShapeLayerList = QWidgetAction(self.projCombo) That is creating a QWidgetAction with the combo box as its parent widget, not its child widget. Try: self.ShapeLayerList=QWidgetAction(None) self.ShapeLayerList.setDefaultWidget(self.projCombo)


1

Embedded cursors are the worst way to program anything. Don't do it. Your code fails because cursors only read one way once. So the interior cursor has to be completely rebuilt from scratch and started over for every record in the outer cursor. For every additional record you have to compare in each table the time it takes to compare the two tables grows ...


1

You just don't quite have the quotes right in your expression.You need double quotes around your datetime. Also, you shouldn't have !DateTime! = as part of it. Try: arcpy.CalculateField_management(out_path_shp, "DateTime", '"' + date_time + '"', "PYTHON_9.3")


2

is creating a standalone .xml file for the feature class an option? ... for instance a temporary XML, which you delete extracting the information you need? If yes, you might want to look into the arcpy command "XSLTransform_conversion". To get acquainted with it, look into ArcToolbox: Conversion Tools > Metadata toolset. The arcpy command only calls this ...


1

It was been rewritten with C, so now it's just renderd. On my ubuntu: which renderd /usr/bin/renderd


0

thank you all, I have solved this problem and there is an little error here. The range of the interpolation is 27000 meters but the extent of the arcpy environment is in degree unit. So the only thing need to do is to unify the unit.


0

While not a Shapely solution, using GeoPandas allows for relatively straightforward projection. For example, if we want to convert a shapefile to ESPG 4326: import geopandas as gpd HabModelEnviro = gpd.GeoDataFrame.from_file('data/HabModelEnviro.shp').replace({-999: None}) HabModelEnviroWGS84 = HabModelEnviro.to_crs({'proj':'longlat', 'ellps':'WGS84', ...


1

Your arcpy.mapping.UpdateLayer is referencing the same layer (updateLayer) in the same data frame for each iteration of your for loop. Thus it is most likely throwing an error because you are trying to update a layer from one map data frame but indicating it is located in a different data frame. Replace with this: arcpy.mapping.UpdateLayer(df, lyr, ...


2

While shapely doesn't natively understand coordinate systems, shapely.ops.transform() can do that along with pyproj. If pyproj.Proj can understand your both of your coordinate systems, then it can be made into a function that shapely can transform with. From the shapely docs: from functools import partial import pyproj from shapely.ops import transform ...


1

You may want to add your vote to the ArcGIS Idea to have a Record macro option in ArcMap: I think a record macro option should increase a lot of people's workspeed with ArcMap, without needing highend programming skills, similar as in MS Excel.


2

It is not included in the ArcGIS install, but adding the iPython Notebook to your workflow sounds like exactly what you're looking for.


2

This worked for me: import arcpy contours = r'C:\TEMP\Contours.shp' con2 = r'C:\TEMP\Contours2.shp' d = {'a': 1, 'b': 2} _list = [1,2,3] string = 'test' lyr1 = arcpy.MakeFeatureLayer_management(contours, 'contours1').getOutput(0) lyr2 = arcpy.MakeFeatureLayer_management(con2, 'contours2').getOutput(0) layers = [globals()[v] for v in dir() if ...


0

Have you tried ListLayers()? I don't see where in-memory is specifically addressed in the Help File, but worth a shot.


0

An alternative would be to deploy your script in a toolbox, which you could access from ArcCatalog. The script, which you expose as a tool in a custom-made toolbox will allow your users to select a datatset and run the script on it. Should you need to run the script on several datatset , you users can use the built-in batch mode (present by default in all ...


3

You could consider exporting to an XML workspace document via the Export XML Workspace Document GP tool. You can input a geodatabase and then all objects including any behavioural ones will get exported. The problem with Copy Features and FC to FC is that they leave the behavioural objects behind (i.e. networks, topology, etc.). May not be relevant for ...


3

I have used this script in the past (Warning, does not copy any topologies, relationship classes, etc): import arcpy, os def ExportSDEtoGDB(sde_gdb, out_loc, out_name, gdb_type='File Geodatabase'): ''' Creates a copy of an SDE Geodatabase to either a File or Personal Geodatabase. This will copy all tables, rasters, and feature ...


0

It seems your "key" field must have type integer and not text. I reproduced your problem with the following snippet: uri = QgsDataSourceURI() uri.setConnection("localhost", "5432", "mydb", "user", "pass") query="SELECT id, CAST (id as text)|| '_' || (ST_DumpPoints(geom)).path[2] as key, (ST_DumpPoints(geom)).geom as points FROM line" uri.setDataSource("", ...


0

Caitlin, here's a tool I created that does what you want, at least as far as your question goes. I haven't added validation, except to set default values, so you may want to do that. In particular, check that filePath exists in case the user manually types in a non-existent path. Note that they can browse to an existing folder, and create a new one. Setting ...


0

I agree with @phloem's comment...this parameter is set when the feature service is published and can be modified (with appropriate permissions) in the Server Manager, in Desktop/Catalog, and the Server Admin directory. You are looking for the Maximum number of records returned by the server parameter. More detail on this page under the "Parameters" ...


0

Here's a revised version of the first part of your script. Notice you don't even need projectGDB, at least to this stage. Untested, and written as a script, not a tool (except for the GetParameter calls). You should probably check if the path exists as well. # Import arcpy module & other helpful import arcpy, os, xlwt # Name Project ext = ".gdb" ...


1

The reason is probably in ArcMap unable to recognize a NoData value set by the IDW tool as either 3.40282e+038 or -3.40282e+038. I'd recommend using SetNull tool for these two values on the result and see if that gets rid of any senseless values (should set them correctly to NoData). If not, a flaw in the input data might be present (I'm unsure if IDW ...


2

You've forgotten to add cur.updateRow(row) in the end of the loop, to save changes.


0

It sounds like what you want to do is delete your old feature class and then rename the result of your erase to the name of your old feature class. Here's the code: if fiabia > fiabib: out_poly = os.path.join(outFolder, nameb + "_er_" + namea + str(count) + "_" + str(cnt)) arcpy.Erase_analysis("fcb","fca", out_poly) arcpy.Delete_management ...


4

I think your question is pure Python rather than GIS but I put together a simple Python script called test.py below to prove that it can be easily done. import arcpy arcpy.CreateFeatureclass_management("C:/temp","test.shp") I placed test.py in C:\temp and used Windows Explorer to double-click it. A DOS window appeared for about 10-15 seconds, and then ...


0

I came across this problem after an "IIS Web Platform" installer silently installed a separate version of Python27; uninstalling it of course didn't fix anything. Creating+running a registry patch file (i.e., text file with .reg extension) with the following contents fixed the issue for me: Windows Registry Editor Version 5.00 ...


1

This code will do the trick I think. It looks for any line with $PHOTO_NUM, and when it finds one it checks three lines below with the use of the linecache module. If $TERRAIN_HEIGHT : is found three lines down, the script performs a cursor to find the replacement value, and calculates the index of the line to do the replacement in. Once this index is ...


3

Don't manually concatenate paths. It leads to errors and makes your code non-portable to other OS's. Use os.path.join instead. For example, replace any instance of projectGDB = path + projectName + ".gdb" with : projectGDB = os.path.join(path, projectName + ".gdb") I believe this will solve your problem, since "F:\GIS\TEST" doesn't end in a path ...


3

The problem may be in how you concatenate the variables to create projectGDB. What you're endiing up with for projectGDB is "F:\GIS\TESTTEST.gdb" Notice there's no slash between the path and the gdb name. I'd suggest using os.path.join(path, projectName + '.gdb') to set projectGDB. Alternately, you could add a slash in front of projectName manually. Also, ...


0

It is a problem of analytical geometry and you can use vector algebra or the direction cosines, for example. for perpendicular lines, a solution is given in How to draw perpendicular lines in QGIS? for parallel lines, you can use the solution of Draw a parallel line (normalized offset) def pair(list): '''Iterate over pairs in a list -> iterate over ...


1

By using the new Layer tree (aka legend or Toc) added by Martin Dobias since QGIS v.2.4, you can load a raster layer to any position of the ToC following these steps: Get a reference of the layer tree root = QgsProject.instance().layerTreeRoot() Create the raster layer object from PyQt4.QtCore import QFileInfo fileName = "/path/to/raster/file.tif" ...


3

In qgis you can use the mmqgis plugin to geocode addresses. How to use this plugin can be found here: http://michaelminn.com/linux/mmqgis in the chapter Geocode Tools


1

If you are using Django (GeoDjango), look at vectorformats, which will produce GeoJSON that you can use directly in Google Maps -- we are using this in production, on a decent sized database, millions or rows and complex polygons, and it works really well. If you want to query Postgis directly, use ST_AsGeoJSON as @underdark says, but note, you need to do a ...


0

I don't totally understand the output of your analysis, but it seems like that for each feature being evaluated you're doing a lot fiddling - copying datatsets, joining them, adding fields, deleting them. If you don't need to do them every time do them once outside your loop. Some benchmarking might help you figure out where the bottleneck is. You can do ...


1

Don't code, use ST_AsGeoJSON — Return the geometry as a GeoJSON element.


2

Years and Months behave differently in several ways that make your expression work for years, but break for months. Any set of year ranges that are positive will work with the original years expression. No set of ranges across multiple years alone can select just dates from a given month. For months you have to set an overall range of all dates regardless ...


0

Solved this using a combination of everyone's suggestions: Code Block - rec=0 def autoIncrement(): global rec pStart = 1 #adjust start value, if req'd pInterval = 1 #adjust interval value, if req'd if (rec == 0): rec = pStart else: rec = rec + pInterval return str(rec).zfill(3) In the Field Expression - 'Object' + str(autoIncrement())


1

I think you just need to set the srs property of the layer layer.srs = "EPSG:4326" layer.native_crs = "EPSG:4326"


1

You have this problem because the field names to be used when you have a join are not the original field names. If you don't need the join anymore, you can use the "remove join" tool. If you do need the values from the joined table, you must include the table name in the field name, like this : !table_name.field_name! If you want to make sure of the ...


0

Try the Unique_values_saver plugin for QGIS. It allows you to save one vector layer for each unique value from a specific field. For instance, for a layer with world countries and regions, I've generated 10 vector layers, each one corresponding to a different region. If you really need the way to do it in Python, just have a look at the source code of ...


1

We can adjust the Field Calculator Code Block to achieve the effect you are looking for. The following assumes that your target field is a Text Field, and has enough length to hold the value produced by the Field Calculation. For example, if we want to prefix our incremental count with the word "Object": Expression: autoIncrement("Object") Expression Type: ...


1

Similar to what the other posters have said. Use arcpy.da.searchcursor and use the where clause. You can then set the where clause to be "where accuarcy > 80" or whatever you want. check out this resource http://resources.arcgis.com/en/help/main/10.1/index.html#//002z0000001r000000


0

In case someone has the same issue, this is my solution. import arcpy fc = "C:\mygdb\myfile" f1, f2, f3 = "EDITOR", "SPECIES", "OBJECTID" clause = arcpy.AddFieldDelimiters(fc, f3) + "= 1" for row in sorted (arcpy.da.SearchCursor (fc, [f1, f2], clause)): print ("{0}_{1}".format(row[0], row[1])) name =("{0}_{1}".format(row[0], row[1])) ...



Top 50 recent answers are included