Questions tagged [code-review]

Questions requesting a review of working code should be asked at the Code Review Stack Exchange

Filter by
Sorted by
Tagged with
0 votes
0 answers
2 views

How to post your code and its link on Stack Exchange? [migrated]

How to post your code and its link on Stack Exchange
0 votes
0 answers
48 views

How to add filter cloud to my NDBI code?

I need to add a filter cloud to my code but I don't know how I can because I'm a beginner. var regions = region.filterBounds(geometry); Map.centerObject(regions); Map.addLayer(regions); var clipToCol =...
  • 9
0 votes
0 answers
64 views

Speeding up WFS layer search in OpenLayers using CQL_FILTER?

I have a function to search feature in my layer and zoom, highlight to search results. But my data is quite large with more than 1 million lines so it takes quite a while for a result to be displayed. ...
  • 19
0 votes
0 answers
36 views

Land Surface Temperature - Landsat 8 - Python

I'm trying to determine if my code for determining land surface temperature is correct. The imagery contains a fire in the middle of October with snow mixed in so temperatures show be nice and ...
  • 1
3 votes
0 answers
104 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 ...
  • 184
0 votes
1 answer
51 views

Treat NA as 0 in custom function for lapp in {terra} R library

I am trying to use the lapp function from the terra rstats library to do some raster-math. But when cells have NA in them, it is giving me the 'wrong' result. Here is my current function and result. a ...
0 votes
0 answers
155 views

A faster way to extract geometry xy of geodataframe

I need a faster way to extract geometry xy of a large dataset which is in a geodataframe format. I have developed a lambda function as below to do that but I need a faster way. The following is a ...
1 vote
0 answers
55 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: /...
  • 455
0 votes
0 answers
207 views

Optimizing code to run faster in Google Earth Engine

I am trying to query properties (~10) from Earth Engine datasets (Temperature, Precipitation, GLDAS outputs, etc.) for a given coordinate point and time range in my dataset (90,000 points). I’ve done ...
0 votes
0 answers
281 views

Finding distance from point to closest LineString given multiple LineStrings efficiently using Python

I have a dataset with many Points and I also have a GeoJSON file consisting of road networks using LineStrings. I want to estimate traffic by seeing which roads have the largest points on or beside ...
2 votes
1 answer
68 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 ...
1 vote
0 answers
25 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 ...
0 votes
0 answers
338 views

Combining image collection from different years using Google Earth Engine

I'm trying to estimate superficial runoff for urban areas, but aparently having problems to generate for 2020. The NDVI collection goes to 2020, but the urban collection only goes until 2019. In line ...
0 votes
1 answer
135 views

Export image collecton with name using Google Earth Engine

I am using GEE for a new collection of images and I need to export it by automating the name of each image, for example, that month one is called January, and so on, how can I do it? My code is here: /...
  • 5
0 votes
0 answers
66 views

Loop over dataframes and extract specific values to generate multiple rasters/plots

I would seek help to revise this script. I need to generate multiple plots. For example, the following code works well ggplot and gsave but I would prefer to use raster, and I tried something such as ...
  • 39
0 votes
0 answers
181 views

Optimizing minimum distance calculations between multiple polygons in R

I have a list of polygons and would like to create a minimum distance matrix by calculating the minimum distance between each possible pair. I am currently using the code below, but this is running ...
0 votes
0 answers
69 views

Speeding up my Python code for reading from Excel, performing geospatial analysis and writing to Excel files

I have written a Python snippet that reads lat and long stored in an Excel file. Converts them to a point which is then used to perform multiple geospatial analysis including buffer, intersection, and ...
1 vote
0 answers
470 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 ...
  • 111
-3 votes
1 answer
88 views

Reducing number of lines / more efficient coding method for field maps [closed]

I am looking for ways to reduce the number of lines when making field maps in ArcPy (note, I am using ArcPy with ArcMap 10.6). I cannot seem to figure out a way, and am stuck with a significant amount ...
0 votes
1 answer
132 views

Calculating Rumple_Index for clipped Inventory Plot LAS files

I have successfully implemented the Rumple_Index example provided in the LidR book. I am now trying to calculate the same Rumple_Index for my forest field plots. I am trying to integrate the ...
  • 11
1 vote
1 answer
109 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 ...
  • 27.3k
1 vote
1 answer
2k 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 votes
1 answer
344 views

Problem Visualizing and Downloading LANDSAT 5 Images With Google Earth Engine

I am new to GEE. I'm working with Landsat images. First, visualizing them in the map, then downloading them and working with them afterwards in QGis 3.6 to obtain certain indexes (NDVI, NDWI, Wetness) ...
1 vote
1 answer
438 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 ...
0 votes
1 answer
79 views

How do I add the soil moisture data I am trying to get onto my Google drive?

Here is my code How do I add the soil moisture data I am trying to get onto my Google drive? var dataset = ee.ImageCollection('NASA_USDA/HSL/SMAP_soil_moisture') .filter(ee.Filter....
1 vote
2 answers
147 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 ...
0 votes
0 answers
109 views

Error when displaying progress bar

My initial code read an image, apply a median filter to it, and save the smoothed image. It looked like this : #Image reading rasterpath = r"C:/Users/SIEXT5646/Desktop/Donnes/2018_gris.tif" ds = gdal....
1 vote
1 answer
198 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 ...
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 ...
2 votes
1 answer
288 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? # ...
5 votes
1 answer
272 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 ...
0 votes
0 answers
2k views

Tool script for GeoJSON to Shapefile

I am creating an ArcMap tool script that takes user input and then takes a GeoJSON file from a specified folder and then opens it in ArcMap as a shapefile. The issue I am running into is that I am ...
3 votes
0 answers
411 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 ...
  • 729
1 vote
1 answer
61 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 ...
0 votes
1 answer
50 views

Creating dictionary of link and its adjacent links (having common vertex) in ArcPy

How do I create a dictionary that has the linkID of a link as key and linkID of touching links as values? I have used this code in ArcPy but it takes a very long time. arcpy.CopyFeatures_management(...
  • 755
0 votes
1 answer
666 views

Google Earth Engine : error: Cannot use 'in' operator to search for 'type' in {"type":"LinearRing","coordinates":

I'm trying to export Sentinel-1 bands with this code in Google Earth Engine but I have recently this error: Cannot use 'in' operator to search for 'type' in {"type":"LinearRing","coordinates": I ...
1 vote
0 answers
151 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 ...
2 votes
0 answers
210 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 ...
  • 195
1 vote
0 answers
178 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....
0 votes
0 answers
28 views

Getting Exported bands must have compatible data types; found inconsistent types: Float64 and Float32 using Google Earth Engine [duplicate]

I'm trying to export sentinel-1 bands with this code in Google Earth Engine but I have recently this error. I didn't have this problem in the past. So here is the code. The code: var start = new ...
  • 9
2 votes
1 answer
262 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 ...
0 votes
1 answer
63 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 ...
  • 29
0 votes
1 answer
89 views

Automate Selection/Copy Features from Selection

I am new to Python and ArcPy, but I would like to automate this process and/or make my code more efficient here. I am basically selecting a layer by attribute, then copying features from the (selected)...
  • 11
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 ...
  • 325
2 votes
1 answer
527 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 ...
1 vote
0 answers
584 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 ...
0 votes
1 answer
344 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 ...
12 votes
1 answer
7k 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 ...
  • 363
0 votes
0 answers
132 views

Why is internal memory not overwritten?

I have the following code in Python for ArcMap to first select a property polygon and then with this selection to intersect the layer which contains lines (sewers) (which pass through or are within ...
  • 1
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"...