8

I find geopandas as the best performer here. import geopandas as gpd shapefile = gpd.read_file("shapefile.shp") print(shapefile)


8

Because you imported unicode_literals, you're passing a unicode literal to GDAL which is expecting a string literal. So, explicitly cast the 'GTiff' arg to a str. E.g. >>> from __future__ import unicode_literals >>> from osgeo import gdal >>> gdal.GetDriverByName('GTiff') Traceback (most recent call last): File "<stdin>...


7

The projections differ in the datum shift values for the conversion from Amersfoort datum to WGS84. The first one is tfm code 4833, and the second is tfm code 15934. GDAL 2.1.0 uses tfm code 4833, while GDAL 2.2.0 and later uses tfm code 15934. The change was done in https://trac.osgeo.org/gdal/changeset/37081 According to the remarks, 4833 is the latest ...


5

To get the folder that the currently open MXD is in you can use arcpy.mapping.MapDocument('CURRENT').filePath, this returns '' (an empty string) if the MXD isn't saved and the full path to the current MXD if it is saved. Using the os.path module you can find the folder the document is in with os.path.dirname, thus os.path.dirname( arcpy.mapping.MapDocument('...


5

If you want to iterate through large datasets, there's a couple of methods you could use: QgsFeatureRequest.setFlags(QgsFeatureRequest.NoGeometry) to avoid calling the geometry for each feature; QgsFeatureRequest.setSubsetOfAttributes() to only call values from a defined field list. So essentially you would iterate only the fields of interest and their ...


4

I am going to show how you can replicate arcgis' python enviroment using conda and then plug arcpy to it. This enviroment shall be isolated from arcgis' python so whatever changes do to it, it shouldn't affect arcgis. The first step is to create an enviroment to enable arcpy at. You can do this with anacoda by typing in the anaconda promt: conda create -n ...


4

Use MakeFeatureLayer_management to make a layer from your shapefile. (This layer will be saved in memory, so you won't actually be saving a layer file anywhere, and it will be deleted when the application exits.) Then pass that layer to SelectLayerByAttribute_management: featureLayer = arcpy.MakeFeatureLayer_management(S_Fld_Haz_Ar, "featureLayer") arcpy....


3

Firstly, why do you think the dataset is being read as all 0's? If you're just looking at the output of print(lc) then you're not seeing the whole array just snippets from the edges (3 elements from each end of each dimension by default). In the example below, I print out the array and it just shows the zeroes at each edge of the array, but then I print the ...


3

One way to do this is with the Append tool (and depending on the amount of common fields among your shapefiles, you may have to modify the field mappings). Pick one of your three shapefiles (or make a copy of it), and append the other two shapefiles to it. Within the tool, select No Test and ensure the three common fields match (right click on field name in ...


3

You need to pass a string to your derived output parameter. Ie. arcpy.SetParameterAsText(7, str(outputPDF)) The result from outputPDF = arcpy.mapping.ExportToPDF(mxd, outputPath) isn't something you can pass directly to the output. Alternatively you could have passed outputPath as that is a string.


3

For Select Layer by Location in_layer and select_features needs to be feature layers, for example created with MakeFeatureLayer (or by adding a feature class to ArcMap and execute code in the Python window using the name of the feature layer from table of contents). So both "Project\project.DBO.Qo" and poly need to be layers. Try: arcpy....


3

I think the issue is that you've created a string of the tuple, rather than mapping the function str to to the tuple. In other words, you're ending up with "(12345, 45678, 910111213)" as a string, instead of ["12345", "45678", "910111213"]. Suggested edit to lines 14-22 (the earlier and later lines look fine): with arcpy.da.SearchCursor(legacyTable,["Parid"...


3

When I use the parameter 'DGN' as 'dgn', it successfully exports as DGN file in QGIS 2.18.22. QgsVectorFileWriter.writeAsVectorFormat( couche_source, enregistre_sous, 'utf8', QgsCoordinateReferenceSystem(2950, QgsCoordinateReferenceSystem.EpsgCrsId), 'dgn', ### change 'DGN' into 'dgn' False, None, skipAttributeCreation = True ...


2

Things have gotten much easier with GRASS GIS 7.4: there is now "grass-session" to call GRASS GIS functionality from Python. To install the stable version use: pip install grass-session For the usage, see the GRASS GIS Wiki or this example GRASS-GIS-Python session.


2

your inputs are strings, GetParameterasText is a string value. convert that variable to an integer... min_scale_int = int(min_scale) max_scale_int = int(max_scale) use your new variable in the rest of your code.


2

In your code select is a results object. >>> lyr = arcpy.MakeFeatureLayer_management ("roads", "layer") >>> type (lyr) <class 'arcpy.arcobjects.arcobjects.Result'> Use the layer name instead. try: if arcpy.Exists("layer"): arcpy.Delete_management("layer") else: print "select doesn't exist" except: pass


2

I found out I was actually creating a table view of a table view. The corrected code reads: import arcpy, os mxdrep = arcpy.mapping.MapDocument("CURRENT") dfsrep = arcpy.mapping.ListDataFrames(mxdrep) #Target folder containing the copied fGDB dbFolder = os.path.join(projFolderPath, "Databases") for dfrep in dfsrep: tablesRep = arcpy.mapping....


2

First, for QGIS3 it is important to have a proper environment. You'll find a solution in the osgeo4w/bin directory. Inside there is a template for calling python.exe with that environment (it is called python-qgis.bat.tmpl or, if it is already renamed, python-qgis.bat). Second, a standalone pyqgis script has to "prepare" or init a pyqgis app, analog to a ...


2

I think it is possible, but is never easy and it maybe requires a deep understanding about programming, QGIS source. Generally speaking, a java program can invoke C/C++ native module(function) through JNI(Java Native Interface). let's suppose you are developing such C++ module(or plugin) . And then the C++ plugin should be built on based on QGIS libraries ...


2

The question you are asking is quite complex to answer comprehensively, but I can give you some structure and you can fill the gaps. My answer is using arpcy, that comes with ArcGIS. You can achieve something very similar with rasterio (see commented lines) First of all, I always like to work directly with the numpy arrays. This can be achieved in arcpy by: ...


2

Dictionaries are useful in situations when you need to transfer attributes between feature classes based on id. From what I understand you dont want spatial join, instead use intersect to calculate the intersecting areas. To add an attribute to the fishnet with the shape area of the intersecting green area and the fishnet cell you can try code below. The (...


2

Yes. So if you were to print cent_featureclasses, you'd see that it only has the feature class name, not the full path. So if you change the workspace, it is looking for those names in the current workspace. So basically all you have to do is add full path list, like so: cent_featureclasses = arcpy.ListFeatureClasses() cent_featureclassesFP = [] for k, v ...


2

You need to specify an output feature class. parcelsFC = os.path.join('temp.gdb',JsonDirectoryLocation) outFc = os.path.join ("temp.gdb", "JsonFeatures") arcpy.JSONToFeatures_conversion(parcelsFC, outFc)


1

To get the messages of the Geoprocessing Service, you need to do two things: Ensure you have a proper message level set on the service. AddMessage = Info, AddWarning = Warning, AddError = Error. (This traverses down, meaning Info will display warnings and errors). You need to perform GetMessage off the result of your execution. From your question, you've ...


1

By using a raster with integer values (1, 100) and one equivalent condition (myarray >= 35, myarray <= 7), following code would work as expected: from osgeo import gdal, osr import numpy ds = gdal.Open('/home/zeito/pyqgis_data/aleatorio.tif') band = ds.GetRasterBand(1) myarray = numpy.array(band.ReadAsArray()) selection = numpy.logical_or(myarray >= ...


1

This is definitely what you don't want to do but.. Option 1 When installing your python distribution you can select the option to set it as main python environment. This is definitely something that the Anaconda installer supports. Alternatively you can manually modify the registry keys pointing to the ArcGIS python executable. An example of those keys is ...


1

I'm not sure this is the very best method, but here is what occurs to me. The difficult part of what you are doing is connecting the right feature class to the correct path and shapefile (and this just can't be automated from what I see in the paths you have outlined). Instead of a reading in a text file, you could just define a dictionary above the function ...


1

I hope you have an answer to this by now, but just in case not I would suggest adding a line after the imports that sets the prefix path. It should look something like os.environ['QGIS_PREFIX_PATH'] = r'C:\OSGeo4W64\apps\qgis'. The code here is for Windows, but it should be similar in macOS. This worked for me.


1

As commented by @Vince: There are an infinite number of potential Albers Equal Area projections. If you want a specific one, you need to specify it, via file name, integer code, or well known string. Even "USA_Contiguous_Albers_Equal_Area_Conic" isn't unique at 10.4.1, because there's also "USA_Contiguous_Albers_Equal_Area_Conic_USGS_version". ...


1

Here would be my workflow: Merge your two polygons together into a single feature class. Dissolve the merged feature class by field CODE. multi_part should be set to SINGLE_PART.


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