mikewatt
  • Member for 6 years, 1 month
  • Last seen this week
Splitting raster into smaller chunks using GDAL?
17 votes

There's a bundled python script specifically for retiling rasters, gdal_retile: gdal_retile.py [-v] [-co NAME=VALUE]* [-of out_format] [-ps pixelWidth pixelHeight] [-overlap ...

View answer
Testing if os.path.exists with ArcPy?
11 votes

A few things: Use "raw strings" to avoid issues with Windows path separators (backslashes) being interpreted as escape characters, e.g. Folded = r"C:\Documents \test.gdb" ^ note the r Is ...

View answer
Reducing number of if statements in Field Calculator code block of ArcGIS Pro
8 votes

You can use in to check for membership: if FIELD in veg: return 'Vegetable' elif FIELD in fruit: return 'Fruit' For bonus points use sets, which offer better performance for this: veg = {'...

View answer
Parallelization of rtree index
Accepted answer
7 votes

One of the authors says no, read operations are not thread safe either. However you could explore using a lock to prevent reads from happening simultaneously. Or running a separate process/thread ...

View answer
ogr2ogr commands with cmd
Accepted answer
7 votes

To debug the command, it can be helpful to echo it instead of running it, to see if any special characters are throwing things off. From inside a bat file, do: echo ogr2ogr -sql "SELECT * FROM 'D:\...

View answer
Packaging third-party libraries with Python Toolbox of ArcPy?
Accepted answer
7 votes

With pure Python packages you can simply place their module folders (cloned from git or wherever) into the same folder as your script files, and then in the properties for your tool check the box to ...

View answer
ogr2ogr too many GCP points - exceeds maximum number of characters in the command line
Accepted answer
7 votes

This page, which lists general command-line options, says there's an "--optfile" argument: Read the named file and substitute the contents into the command line options list. Lines beginning with # ...

View answer
ArcPy While loop not ending
Accepted answer
6 votes

buffCount looks to be a string, you need to convert that to an integer

View answer
rasterio "invalid dtype: 'bool'"
6 votes

If you call rasterio.dtypes.check_dtype(np.bool_) you'll see that it's not a known dtype, because gdal doesn't support a true 1-bit dtype. GDT_Byte is the smallest. The list that rasterio is ...

View answer
Getting available GDAL raster drivers in Python
Accepted answer
5 votes

Checking the Python docs I see: gdal.GetDriverCount(), returns an int gdal.GetDriver(int i), returns a Driver() gdal.Driver(), has ShortName and LongName attributes So chaining them together: import ...

View answer
Numbering like values in new attribute table field using field calculator of ArcMap
5 votes

If you're talking about ArcMap, you could try something like this in the field calculator's Python code block (untested): lookup = dict() def get_id(value): global lookup try: uid = ...

View answer
Spatial Join Ouput Attributes Differ Based on Input FC or SHP
5 votes

The attribute mixing, as you say, is controlled by the merge rules. If you didn't explicitly modify the rules, it will default to "first". According to the docs: The merge rule property of an ...

View answer
Create default ArcToolbox parameter with current folder location of ArcToolbox .tbx
Accepted answer
5 votes

What you're looking for is the __file__ variable, which in this case will contain a path such as: C:\Users\users\Documents\ArcGIS\Toolbox.tbx#Script.InitializeParameters.py So just do a pathname = ...

View answer
Printing geographical centroid coordinates of georeferenced image in CSV file
Accepted answer
4 votes

To go from image coordinates to geographic coordinates, get the geotransform using img.GetGeoTransform(), then the transform is as follows: gt = img.GetGeoTransform() x_pixel = cX y_line = cY x_geo =...

View answer
RGB composite of Landsat 8 bands not plotting correctly (Python, GDAL)
Accepted answer
4 votes

The issue is that array.astype() is not applying any stretching or scaling, you need to do that yourself to make the input range of 16-bit values (2^16-1 == max of 65535) fit into an 8-bit integer (2^...

View answer
Difference between classification methods with Laspy
4 votes

LAS 1.2 has a classification byte, which is 8 bits. However 3 of those bits are used for the flags (withheld, synthetic, and keypoint). With laspy, classification accesses the 5 bits that LAS 1.2 ...

View answer
Rasterio.features.rasterize
4 votes

shapes : iterable of (geometry, value) pairs or iterable over geometries. `geometry` can either be an object that implements the geo interface or GeoJSON-like object. A list, tuple, or ...

View answer
arcpy.da.InsertCursor generating empty polygons?
Accepted answer
4 votes

Try manually specifying the list of input fields, and include the special "SHAPE@" token to return a geometry object for that field. I suspect the wildcard you're using isn't returning the full ...

View answer
Searching for NULL values in feature class table
4 votes

If you're after a raw count of null values in any field: sum(sum(v is None for v in values) for values in arcpy.da.SearchCursor('some_layer', '*')) If you want to know specifically which rows/fields ...

View answer
cannot read raster of 14 MB
Accepted answer
4 votes

You'll notice in the dict there that the file has deflate compression, so on the disk it may be 14MB but rasterio is trying to uncompress it as you read the whole band. We can figure out the ...

View answer
DEM to bmp for cnc carving query
4 votes

This is likely a difference in bit depth. Whatever format the DEMs are provided in probably stores each pixel as a 32 or 64 bit float. These can store values out to a handful of decimal places and ...

View answer
How to read part of a TIFF as array and export it with its correct coordinates using GDAL?
Accepted answer
4 votes

That will work as long as your images aren't rotated, i.e. gt[2] == gt[4] == 0. Have a look at rasterio if you're not tied to straight-up gdal: https://rasterio.readthedocs.io/en/latest/topics/...

View answer
Python Toolbox parameters set up error: Value is Required
4 votes

Unfortunately the "parameterType" is a read-only property, so you can't just change that parameter from "Required" to "Optional". You can work around this by setting it to "Optional", then performing ...

View answer
Making sense of why and when polyline matches what is shown in Google Maps
3 votes

Replace all of the double backslashes (\\) in the original with single backslashes (\) then try the online decoder again: ezdvBcps}Lt@W@F@BVKl@UK]Wc@}@kAOKBEzA{BdA}Ab@s@LBf@RjARZBv@?rAAfBIX?f@FLBf@^b@...

View answer
Creating Python OSGEO/OGR geometry with M-values (not using WKT)
Accepted answer
3 votes

Try AddPointM() instead of AddPoint(): AddPointM(Geometry self, double x, double y, double m) https://gdal.org/python/osgeo.ogr.Geometry-class.html#AddPointM

View answer
Inserting space into string using ArcMap Field Calculator
3 votes

No need for wildcards, the replace() method searches the whole string, as you can see if you test it out in the Python interpreter: >>> "Test string with F'target in the middle"....

View answer
GDAL change Band Block size
Accepted answer
3 votes

Use the TILED=YES creation option of the GTiff driver, e.g: gdal_translate -co TILED=YES -co BLOCKXSIZE=512 -co BLOCKYSIZE=512 src.tif dst.tif

View answer
Convert WKT Polygon to ESRI Geometry String in Standalone Python Script
3 votes

Here's my best guess using shapely. I haven't looked into the spec, just going off of your example: import json import shapely.wkt wkt = 'Polygon ((-95.92442111883893574 30.18765532529553752, -95....

View answer
GDAL: Change no-data value of GeoTIFF without having to recreate the whole GeoTIFF
Accepted answer
3 votes

Since it seems GEE doesn't understand GDAL's PIXELDATA metadata and is treating it as an unsigned datatype regardless, maybe a workaround is just defining the nodata value as the unsigned equivalent ...

View answer
Error when assigning a spatial reference to a PointGeometry in arcpy
Accepted answer
3 votes

Despite what the documentation suggests (and how Python objects normally work in 99.9% of cases) you can't use keyword arguments when creating geometry objects. Using positional arguments only should ...

View answer