Hot answers tagged

9

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


7

First, run MakefeatureLayer to enable the Ratio Policy on a specific field. Then, run the FeatureLayer though Intersect, it will honor the split policy rule. The field specified must be Numeric.


6

Using the Vector Overlay->Extract/clip by extent tool in the processing toolbox will produce almost what you want: But as you can see you get the bounding box not the actual boundary of the raster. I had hoped you could use the Vector geometry->Minimum bounding geometry but that only works on vector layers. So if you must have the exact matching ...


5

you can do a query (select by expression in the attribute table) and then save the elements selected by the query (query based on attributes) or make a manual selection in the map windows and save/export the layer using selected features only ...


4

Create a grid (vector -> research tools -> create grid) covering the area of the city you need to be covered. Your gridsize seems to be about 100 by 100 m, use this for vertical and horizontal distances. Make sure you get polgyons, not any other type of grid. Make sure your grid-polygons all have an ID. Use vector -> data management tools -> join ...


4

You won't be able to use Clip to extract a continental US unless you already have another continental US feature. You can, however, Select and Export the features you need. Choose the Select by Rectangle tool. With the Select by Rectangle tool, draw a rectangle around the continental US. After you complete the rectangle, your selected features will be ...


4

You just need to replace: out_raster =(out_folder,raster) With: out_raster = os.path.join(out_folder,raster) Or out_raster will be a tuple: ('C:\\folder', 'raster.tif'), instead of a path: 'C:\\folder\\raster.tif'


4

You cannot clip a vector layer with a raster layer, so do the following Use Processing Toolbox > Layer Tools > Extract layer extent for the scanned map layer. Now you can use Processing Toolbox > Vector overlay > Clip and choose the OS data shapefile as Input layer and the extent layer generated in Step 1 as the Overlay layer.


3

The -spat parameter in ogr2ogr https://gdal.org/programs/ogr2ogr.html#ogr2ogr affects all available layers. This selects data withing the given rectangle from all layers if you write only the name of the datasource into the command but not the layername. So just "...input.gpkg" instead of "...input.gpkg selected_layer". ogr2ogr -f gpkg -spat 100000 6000000 ...


3

Reproject your vector and raster data into a projection that uses meter or feet units depending on your region and try the clip tool again. WGS84 can cause a problem because the pixel sizes of the raster data are in decimal degree. Using a projection of meter unit, for example UTM, can solve the problem.


3

I would recommend referencing The raster calculator No-data values which goes through how to use the raster calculator to perform some operations on raster layers. We will also explain what are no–data values and how the calculator and other algorithms deal with them. Another option may be in terms of NaN values occurring in your DEM, from what I'm aware,...


3

QGIS3.0+ Let us assume we have a buildings layer (orange polygons: A, B, C) which is linked to another layer parcel (gray polygons: 101, 102, 103) by Parcel_Num attribute field. We can use Geometry by Expression tool in Processing Toolbox | Vector geometry. Click on the large Epsilon mark to open an expression dialog window: Expression is: intersection(...


3

Using Expression in QGIS Geometry by Expression tool - Provided: Road layername is roads and it has road_no field to represent the road name (A, B, C) State layername is states and it has state_no field (1, 2, 3) Start Geometry by expression tool in the QGIS Processing toolbox - Vector geometry Select your roads layer as input (1), and choose Line as ...


3

You can clip a raster by a vector easily, so first step is to convert your raster to vector. GDAL > Raster Conversion > Polygonize. You will have polygons with attribute called DN with values 0 and 1. Select all polygons with value 1 with expression like DN = 1 Use GDAL > Raster Extraction > Clip raster by mask layer. Select the polygonized layer as the ...


3

If you create a clipping layer with only the circular feature to use, your code can be simplified in this way (I use my own paths): from osgeo import gdal, ogr OutTile = gdal.Warp("/home/zeito/pyqgis_data/cut.tif", "/home/zeito/pyqgis_data/utah_demUTM12.tif", cutlineDSName='/home/zeito/pyqgis_data/boxes.shp', ...


2

I wonder if your dbase file is incomplete? The maximum size of a single dbase file is 2GB, yours is very close to the limit. It is odd, both your dbf files have the exact same byte count but the shp file is smaller. ESRI recommends using a file geodatabase instead of a shapefile. Shapefile specifications: https://www.loc.gov/preservation/digital/formats/...


2

Select the grid polygons that intersect with your base layer and than invert the selection and delete them (In QGIS 3.2 Vector > Research tools > Select by location)


2

This is not an answer, but it is too long for the comments. When making a call to a program outside python, I prefer to use subprocess. It allows you to see any error messages that result (e.g. thrown by ogr2ogr). Something like this: import subprocess callstr = ['ogr2ogr', '-clipsrc', file_that_clips, clipped_file, ...


2

Assuming the layers are all in the current MXD, you could try something like this using Python and arcpy: extentOfInterest = arcpy.Extent(xmin, ymin, xmax, ymax) mxd = arcpy.mapping.MapDocument("CURRENT") for layer in arcpy.mapping.ListLayers(mxd): if extentOfInterest.overlaps(layer.getExtent()): print "Layer overlaps and will be processed: " +...


2

It is correct that the two ways of clipping treat your quota consumption differently. You are free to continue using the Clip API with the understanding that it will be decommissioned and replaced with a new way of server-side clipping. To start doing things the "new way", please see the documentation here. Example from the documentation: { "name": "just ...


2

You can also use the following: for feature in features: if "_clipped" in feature: continue else: arcpy.Clip_analysis(in_features=feature, clip_features=clip_feature, out_feature_class=feature+'_clipped') The continue statement in Python returns the control to the beginning of the for loop skipping the features which have _clipped ...


2

You can replace the last two lines with: for feature in features: if '_clipped' in feature: arcpy.Delete_management(in_data=feature) Which will delete clipped fc outputs. Then rerun the clip script. This is easier than checking for unclipped fc and clipped fc and clip if clipped fc is not found. Will be slower though since all fcs are clipped ...


2

This is easier with arcpy. If you dont want an arcpy solution I can delete my answer. Script will list all feature datasets in database, and for each list all feature classes and then clip with specified clip feature. Outputs will be placed in the same feature dataset and with '_clipped' appended to name. Make sure you have no feature datasets or feature ...


2

I can propose how to clip part of the source image by 512*512 (or whatever size) tiles Create AOI by which you clip source image Perform Raster Extraction Clipper (Qgis 3.2) Using plugin Qtiles (available in Qgis 2.18) perform extracting tiles 512*512 into some directory Then you have a lot of tile divided into several subdirectories respective to zoom ...


2

From the Processing Toolbox run the "Extract layer extent" algorithm.


2

Mmm, really it depends on what you need the final outcome to be. Assuming you would want the outcome to be compatible in later analyses with the file you are clipping it to, I would re-project it first, then clip it to the file! If you would do it the other way around, the end result would probably not be perfectly clipped. That being said, observe caution ...


2

Heavy raster processing tasks are perfect candidates for multiprocessing. Input: Script: import time, os t0 = time.time() import multiprocessing from multiprocessing import Pool import arcpy mosaic=r'D:\Bulk_Data_Supply\Aerials_2010_2011\RURAL.gdb\TILES' shpFile=r"C:\SCRATCH\fish_net.shp" def clipMany(aList): shp, out_f=aList arcpy....


2

sf::st_intersection() will work with the last version of sf (0.7-3). I don't know why it was not working in the previous version.


2

If you have access to the Spatial Analyst extension, use the Conditional tool: Con(ClipRaster, SourceRaster)


2

You're on the right track by polygonizing the raster. Currently you're trying to polygonize the elevation raster, and the tool is trying to create a separate polygon for every elevation value (ie a polygon for 3500', another polygon for 3501', etc.) You could select and merge all the polygons with values > 3500, but there's a much faster method. First create ...


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