Questions tagged [code-review]
Questions requesting a review of working code should be asked at the Code Review Stack Exchange
86
questions
30
votes
2
answers
7k
views
Using OGR and Shapely more efficiently? [closed]
I'm looking for some suggestions about how to make my python code more efficient. Normally efficiency doesn't matter for me but I am now working with a text file of US locations with over 1.5 million ...
25
votes
3
answers
15k
views
Speeding up plotting of polygons in R
I want to plot the country borders of North America over a raster image depicting some variable and then overlay contours on top of the plot using R. I have been successful in doing this using base ...
12
votes
1
answer
8k
views
Counting points in polygons with sf package of R?
I'm quite new to R and especially GIS with R. So recently I had to proceed to a quite simple analysis: counting health centers (points) per administrative unit (polygons). Quite common process in ...
9
votes
2
answers
12k
views
Maximizing Code Performance for Shapely
I've written this code in order to calculate the percent cover of grassland within a national park, within 20km^2 of points of recorded occurrences for a species. It is designed to only consider the ...
6
votes
4
answers
2k
views
Optimising and speeding up ArcPy code? [closed]
Again my lines of surface runoff. I made a script, solving the issue when lines cross other lines. Something like generalization. Like on the picture below. The problem is that I have to solve 30 ...
6
votes
1
answer
327
views
Optimizing Intersection Area Loops on big layers using PyQGIS
Using 3.10.1-A Coruña on Windows 10
I am looping over some (10) national shapefiles and finding intersection and areas but the process is very slow.
I have two loops - one loop for each postcode and ...
5
votes
1
answer
1k
views
Renaming 1,200 rasters in File Geodatabase using ArcPy
I've been tasked with renaming a large amount of raster files within a file geodatabase (using ArcGIS 10.2.2).
I'm taking weather data which has a name format as such: "G"mmddhhhh
I'm trying ...
4
votes
2
answers
3k
views
Filling dictionary with list of row attributes using arcpy.SearchCursor
I have a dBase database file and I'm viewing and editing the table in ArcGIS Pro. I want to use the arcpy.da.SearchCursor function to fill a dictionary and create a key-value pair by iterating ...
4
votes
2
answers
466
views
ArcPy UpdateCursor deleting duplicate records?
I am working with .dbf files. I have two columns of data that have duplicates. A column of parcel numbers with duplicates and a column of letters that are duplicated. I want to delete all parcel ...
4
votes
0
answers
62
views
Looking up whole time-series for specific point from 45 GB file
I want to look-up 8760 times for a single lat/lon combo in less than a second from 43.82 GB file of wind data containing:
8760 times (every hour in a year)
721 latitudes (every 0.25° from -90.0° to ...
3
votes
2
answers
105
views
Improving ST_Intersects performance in PostGIS
I have the following query, but it takes a long time to run. I tried creating an index, but there hasn't been much improvement. Any suggestions?
CREATE INDEX temp_clusters_geom_idx
ON temp_clusters
...
3
votes
0
answers
475
views
Alternative to Rasterio Mask module for clipping a raster using masked geojson
I am clipping a raster (.tif file) using a mask vector (.geojson) file.
with rasterio.open(url) as src:
out_image, out_transform = rasterio.mask.mask(src, shapes, crop=True)
But, this ...
3
votes
1
answer
297
views
Optimising Large Spatial Queries in SQL
I'm sure similar answers have been given elsewhere but no matter what I have tried I am unable to optimise this query.
Details: TableA has 3.5mill records TableB Had 57000 records but I have ...
2
votes
1
answer
4k
views
Fastest way to extract a raster in R (improve the time of my reproducible code)
I'm wondering if I have maximized the speed at which a mean of an area buffered around a point in a raster can be extracted.
Fastest way I have ever found to extract a raster, with the pre-cropping ...
2
votes
1
answer
73
views
Reducing number of for loops in ArcPy code
I want to clean this code in such a way that there are not so many for loops. For loops in the following code are placed to trap FCs in multiple group layers and do some work on them. My Data in TOC ...
2
votes
4
answers
92
views
More Efficient Conditional Statements - ArcGIS Field Calculator
I am new to Python and have successfully created the following statement that writes a change period value (01 or 02) based on the municipality and date fields. I am wondering if anyone could point ...
2
votes
1
answer
360
views
Creating NDVI from raster using ArcPy
I have to create NDVI's for multiple raster images, and so want to find out the most efficient way to do it.
The code below works, but I wondered if there was a more efficient way to do it?
# ...
2
votes
1
answer
70
views
Counting only data points which are within a specified radius of other data points?
I wanted to know if I am on the right track here with what I am trying to do. I have two shapefiles, the first contains point data for all the businesses in DC and the other contains point data all ...
2
votes
1
answer
621
views
Populating layer field with dict.values() in PyQGIS 3?
I've coded the script below in PyQGIS 3 to get the azimuth of starting or ending points for a line layer that touches a border. It works fine, but I want to populate the azimuth field layer with the ...
2
votes
1
answer
218
views
Speeding up raster to point set function
I have written the following function that takes a raster (always non-skewed) and returns a set of points. As I'm executing it millions of times in my queries, I'd like for it to be super-optimized (...
2
votes
0
answers
142
views
Improving performance of spatial intersection and aggregation query
Edit:
Per a comment, here is some more context and the basics of what I'm looking to do, that I think would better enable someone to offer input from a first principles perspective. Its a lot of ...
2
votes
0
answers
351
views
Making Dijkstra faster
I would like to compute shortest path between 2,5 millions pairs.
I created table with id, origin, the nearest node of origin, destination, the nearest node of destination.
I also created index on ...
2
votes
0
answers
664
views
Moving Feature Class to Different Feature Dataset within Same File Geodatabase using ArcPy?
I want to progammatically move a feature class into a different feature dataset within the same file geodatabase. I'm wondering if there is a way of doing this without including code to rename and ...
2
votes
0
answers
91
views
Unable to get points in buffer on selected feature in QGIS using Python?
I have to create a 1.5 km buffer on each latitude/longitude of layer A. I would like to know how many points of line B will be inside the buffer of layer A. I used the following code but it takes too ...
2
votes
0
answers
171
views
How to speed up my script? [closed]
I am looking for the way to speed up my script. It is working fine, I mean, the final output is as required, but it is clunky and really slow. It is slow because of the double 'for..in..' loops, I ...
1
vote
1
answer
575
views
Improving poor performance of ArcPy update cursor with ArcSDE and Editor? [closed]
I am using ArcGIS 10.5 in an ArcSDE environment.
I have two tables, they are the exact same table schemas, but one is being edited and those edits are being pushed to the main table. I am a little ...
1
vote
1
answer
124
views
Improving PyQGIS distance matrix efficiency
I have written a custom processing tool, which I use within a large graphical model in QGIS. I am looking for a way to speed it up.
First step of this processing tool is to connect every point of one ...
1
vote
1
answer
668
views
Easier Way to Record Yearly Mean NDVI
For my Google Earth Engine project, I am finding the mean NDVI for each year between 2000 and 2020 in protected areas a part of the World Database on Protected Areas (WDPA). As an example, I have ...
1
vote
1
answer
295
views
Arcpy Delete Multiple Layers
I'm writing an add-in for Arcmap and at the end of it I am left with multiple layers from buffers, joins, and selections. I am trying to delete these layers before the add-in finishes so to keep the ...
1
vote
1
answer
3k
views
Converting TIFF file and changing CRS
Is there a fastest way to:
Load a .tif file;
Convert it into GeoDataFrame; and
Change Coordinate Reference System?
I am using Python, and what I tried to do is:
Use rasterio to check if the Source ...
1
vote
2
answers
176
views
Making ArcPy code run faster
I have an ArcPy code that I am using to find various characteristics about certain watersheds in Indiana. I start with a shapefile of all 800 watersheds and go through it row by row and perform a ...
1
vote
1
answer
66
views
Improving ArcPy script for ArcMap to only return rows of selected polygons instead of all polygons in layer
I am debugging a code provided to me that merges two polygons and alters the fields of "FID1' and "CALC_AREA."
I have realized that the current code searches every layer in the map document for ...
1
vote
1
answer
49
views
Speeding up script to flag nodes within 100 feet of segments using PostGIS?
I'm working with two datasets, attempting to flag when an intersection is within 100 feet of a network subset. There are over 40,000 intersections and my network is ~ 1400 segments.
The problem with ...
1
vote
1
answer
2k
views
I can not export the image to the drive in Google Earth Engine (GEE)
Whenever I try to export to the drive the image gives me the following error:
Error: Invalid argument: 'image' must be of type Image.
This is my code:
var mod11 = ee.ImageCollection("MODIS/MOD11A2"...
1
vote
1
answer
553
views
Using accumulate function for temperature units?
I am working on a piece of code that is designed to aggregate growing degree days for a particular region.
To start, the equation for growing degree days is: Daily GDD (°F) = Daily Average ...
1
vote
1
answer
618
views
Reducing hourly rainfall data to monthly data for particular period of time and making a timeseries chart
I am working with GSMaP image collection (hourly rainfall data) in Google Earth Engine. I would like to make a script which is calculating and making a chart of sum rainfall in particular location ...
1
vote
2
answers
498
views
Simpler Method to Map Fields in Spatial Join
I've cobbled together a script, part of which creates field mapping to sum fields in a spatial join. It took 13 lines of codes just to define which fields I want summed in the output. Is there a ...
1
vote
1
answer
338
views
Improve Python script logic/structure for erasing features with arcpy
How can I define (and therefore, research/learn how to use) the Pythonic concept for writing a script that can take one input variable, compare it against a list of other variables, and then holding ...
1
vote
0
answers
77
views
Speed up intersection on large polygons with PyQGIS?
Is there a way to speed up my script? I am new to PyQGIS. I am using QGIS 3.16.
What I need: I have 50 polygons (up to 1.675.000 hectares, mean 420.000 ha; one shapefile per polygon) and for each of ...
1
vote
0
answers
59
views
Get file path of Geopackage with PyQGIS [duplicate]
I want to get the Geopackage file path where my layer is stored in.
Layer = QgsProject.instance().mapLayersByName('DAT')[0]
print(Layer.source())
But this only gives me the path with layer pointer:
/...
1
vote
0
answers
31
views
TPI calculation by PDAL [closed]
Is there a convenient way to calculate the topographic position index by PDAL?
I have LAS file and what I do is iteratively for every point calculate the TPI. The coordinate information I take from ...
1
vote
0
answers
822
views
Downloading and merging 0.5 minute WorldClim data for (long) list of coordinates using R
I want to download temperature and precipitation data from WorldClim for a huge list of coordinates. I am working in R, and have a solution using getData() from raster(), but it's going to take ...
1
vote
0
answers
167
views
Optimizing Google Earth Engine cloud cover for Sentinel 5p
I am trying to generate cloud free Sentinel 5p images, I have a basic cloud detection code working but it runs very slowly (most likely due to nested map and reduce features).
Is there a way to do ...
1
vote
0
answers
270
views
QGIS 3.8 Python Code for calculate area
Is this the the best solution to calculate the area of the features?
parent = iface.mainWindow()
mc = iface.mapCanvas()
fldname = "m2" #field which has the values for squaremeters
myLyr = mc....
1
vote
0
answers
665
views
Calculating nearest distance between points and Spatial Polygons in R? [closed]
So right now I have pretty large datasets, about 200,000 (lat,long) locations and a Large SpatialPolygonsDataFrame with a polygons list of length 428386 spread in a single city of around 450 square ...
1
vote
1
answer
434
views
Making looping through line segments for vertex points faster?
I am trying to speed up some current code that I have for looping through lines, getting their segments and ultimately the vertex points in Python.
Can anyone recommend a faster method than what I ...
1
vote
0
answers
787
views
Finding a more efficient way to execute a long-run python script [closed]
I'm executing a python script which does these steps:
iterates through 19 features (makes pairs "each one with each other", order doesn't matter: A-B = B-A)
Creates Closest Facility Layer
Adds ...
1
vote
0
answers
48
views
Improve my arcpy script for simple querying [closed]
I am quite new to coding python in arcmap so I would like to get my code reviewed and hopefully improved.
I have two Shapefiles, one contain polygons of cities borders and the other is points ...
1
vote
0
answers
401
views
Improving Ray casting algorithm
I have been using the following function below which have been working well to decide if a point in the polygon but once I have many points which is building the polygon say over few thousand it seems ...
0
votes
1
answer
66
views
Getting same result with less code with PythonWin ArcPy? [closed]
I have finished writing code and it does what I need without having any error. However, I am wondering if there is any option to get the same result in fewer lines, pecially the for loop inside the ...