Hot answers tagged

5

I got an orders of magnitude speed-up simply by moving two if statements just underneath their corresponding fiona.listlayers calls. if (featureName == "HydrographySrf") if (bldgName == "StructureSrf") I just went from taking over 5.5 hours of parsing down to less than 2.5 minutes. Sorry for getting things spun up on what is otherwise an easy fix.


4

You can use the \W (upper case W) to match any non-alphanumeric characters. If using regexp_replace() it seems you need to escape the backslash, so it becomes \\W (thanks, Joseph!) For example regexp_replace( '=+&hello%%£world','\\W+','_') returns _hello_world If using the python equivalent function re.sub(), you probably won't need to escape ...


3

There is a python module called rasterstats that does compute zonal statistics. For each Polygon, your fields, there will be the underlying rastercells accumulated by SUM, MEAN, MIN or MAX. You find more infos and examples here: https://github.com/perrygeo/python-rasterstats Otherwise you find an example without this module here: ...


3

Nice question! Say that you have a vector layer referenced: lyr = iface.activeLayer() At this point, I assume you start an edit session and digitize some features. Now you can use the QgsVectorLayerEditBuffer class, in this way: if lyr.editBuffer(): print len( lyr.editBuffer().addedFeatures() ), "features to add!" addedFeatures gives you a ...


3

Use layer.GetNextFeature() from osgeo import ogr driver = ogr.GetDriverByName("WFS") wfs = driver.Open("WFS:http://geodienste-hamburg.de/DE_HH_WFS_INSPIRE_A3_1_Statistische_Einheiten") # This is a public WFS with open data layer = wfs.GetLayerByName("Stadtteile") # Some polygons, possibly multipolygons # A random point inside one of them ...


2

Add an AttributeExposer, expose the fme_feature_type attribute Connect the AttributeExposer to a AttributeCreator to push fme_feature_type out an attribute (named fme_feature_type below) In the PythonCaller, get your attribute by: layer_name = feature.getAttribute("fme_feature_type")


1

Essentially my project was to loop through 7 folders: 1-7 representing days and in each folder there were thousands of csvs containing pickup and dropoff locations. You will have to mess around with your path names. I also never parsed GPX files, I am not sure how different that is from reading csvs. But this script should give you a decent understanding of ...


1

After some search I finally found a working solution: As I saw that layer.maximumValue(idx) always kept the same value until I commited changes, I added the number of new elements and that are pending to be commited to this variable. This way I always get serial (autonumeric) number. Idea taken from here: def openProject(): from qgis.core import ...


1

The only line that is going to generate that error is return(subsetOut) If subsetOut is referenced before assignment it means none of the above if and elif conditions matched as true. There's no else to catch anything else. You seem to be comparing a selection value with a numeric. I suspect the selection values are character values (since a selection ...


1

It could be that your GDB files (which are self-contained databases) have indexes designed to make these kinds of operations very fast for ArcGIS. If OGR (which is what Fiona uses to read GDB files) supports these indexes, you should be able to get a significant speed up if not the same performance as ArcGIS. The section at ...


1

You could use: iface.mapCanvas().saveAsImage( "myGeoreferencedView.png" ) It exports both PNG and PNGw files. The latter is known as World file and contains coordinate information.


1

Answered at https://github.com/mapbox/rasterio/issues/710. Example reading a 30x30 window into a 3x3 array where overviews (if available) would kick in. arr = np.empty(shape=(3, 3)).astype(src.profile['dtype']) arr = src.read(1, out=arr, window=((0, 30), (0, 30))) arr array([[9195, 9116, 9134], ...


1

I found that using "isMultipart" returned any features that had more than 1 feature part AND any features that had donut holes. I created this script that will instead loop over the features, check the the number of actual objects, then select all features that have 2 or more geometry objects via SelectLayerByAttribute_management. import arcview, arcpy ...



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