11
votes
Symbolising point shapefile in QGIS: half blue half red colored point
To just show another possibility: you can use Geometry Generator and create wedge buffers. The advantage is that A) you have only one symbol layer and B) you can use it to create even more complex ...
9
votes
Getting the number of features in shapefile without opening it using Python
I think it is not possible to get the feature count without opening at least some part of the shapefile but for sure it is not necessary to read all data.
With GDAL and Python
from osgeo import ogr
...
9
votes
Accepted
Converting GEDI HDF5 LiDAR data to a format readable in GIS
First, I have to say that there are too many datasets that I don't know what it means in the file.
I will try to explain step by step:
Import necessary packages
import h5py
import pandas as pd
import ...
9
votes
Symbolising point shapefile in QGIS: half blue half red colored point
In QGIS you have to go to: Layer Properties > Symbology > Symbol selector > Simple Marker > scroll down and select the half circle > Rotation: 90°
For the second half circle: add ...
8
votes
Accepted
TypeError when converting shapefiles to KMLs using PyQGIS
According to the documentation the first argument should be a QgsVectorLayer, which is why you are getting the unexpected type error.
You are also missing the QgsCoordinateReferenceSystem parameter.
...
8
votes
Accepted
Selecting features and save them as a new polygon while removing the selected features from input polygon in QGIS
Once you have made your selection, you can
Edit > Cut features and then
Edit > Paste features as... > Choose between New Vector Layer or Temporary Scratch Layer
Make sure the layer you are ...
7
votes
Determining on which side of line points are located using QGIS
In PyQGIS 3 there is a handy method available, namely segmentSide() from the QgsGeometryUtils class.
Let's assume there are two layers: a line layer with a single feature, and a point layer with nine ...
7
votes
Separating layers based on labels
The easiest way is splitting the layer using the function Split vector layer
You then select the attribute field of your choice for classifying the features
7
votes
How to manage files generated when saving selected features on QGIS
These are all parts of a Shapefile.
The best way to manage them is to not create them in the first place!
Consider saving your files as GeoPackage (GPKG) instead. It's a more modern format - ...
7
votes
Failed to export from shapefile to CSV in QGIS
The error message is quite explicit and clear:
a field with this name already exists.
It seems you have two fields with the same name (maybe truncated by the fieldname length constraint in ...
7
votes
Deleting shapefile after removing it with removeMapLayer using PyQGIS
Even if you keep in mind several things regarding your code:
work with a real path to the shapefile instead of "XXXX/input1.shp" i.e. apply either source_layer.source() or source_layer....
7
votes
Accepted
Clearing some lines in QGIS leads to features with no data
Using the vertex tool to delete feature vertices will not delete the feature. It deletes the feature's geometry only. It will no longer appear on the map canvas, however, the feature will still exist ...
6
votes
Accepted
How to use a variable from a shapefile coming from another different shapefile in field calculator in QGIS
This expression returns the attribute value from the x2 field of layer B, where layer B's ident is equal to layer A's ident.
attribute(
get_feature('B', 'ident', "ident"),
'x2'
)
...
6
votes
Importing squares indicated through EPSG:3035 into QGIS and merge with shapefiles
In Excel,
Add two empty columns next to Gitter-ID.
Split Gitter-ID text into different column with "Data > Text to Column". Use firstly N, then E as separator/delimiter. Enter Y and X ...
6
votes
Accepted
Importing squares indicated through EPSG:3035 into QGIS and merge with shapefiles
You are correct, Gitter-ID are CRS3035 coordinates.
To use them in QGIS, first create columns with the N & E parts of the coordinates (split column by width in Excel), and export that Excel sheet ...
6
votes
Determining on which side of line points are located using QGIS
You can also use QGIS expressions for this, using this expression to get a 0 or 1 output for each point, depending on which side of the line it is (see below for curved lines). The solution is based ...
6
votes
Getting the number of features in shapefile without opening it using Python
Yes it's possible, for example using ogrinfo at the command line.
From your command line shell
Here in bash:
ogrinfo -ro -al -so my_shapefile.shp | grep -i "Feature Count"
Feature Count: ...
6
votes
Getting the number of features in shapefile without opening it using Python
If you only need the number of features, use the standard Python module struct (used by pyshp). You only need to read the first bytes of the dbf or the .shp files (Raw Binary Files):
a) .dbf file : ...
6
votes
Accepted
Batch replacing of layer file paths in QGIS
Save your project as QGIS files (.qgs), not the default (zipped) .qgz file - or unzip the .qgz project file. Then you're able to open the project in a text editor in a human-readable format. There, ...
6
votes
Accepted
Does GDAL have an error with calling multiple functions on the same line of code?
This is a GDAL python "gotcha":
Python crashes if you use an object after deleting an object it has a relationship with
...
This problem can manifest itself in subtle ways. For example, it ...
5
votes
Getting the number of features in shapefile without opening it using Python
Another option is to use the PyShp library
# imports
from os.path import normpath
from shapefile import Reader
absolute_path_to_shp = normpath("C:/Users/taras/files/cluster_test.shp")
shp =...
5
votes
Shapefile with CRS associated to it without the need of a .PRJ?
It's not possible. The only way Shapefile can have determined CRS is to write it in PRJ file.
5
votes
Accepted
Failed to reproject/convert a projected shapefile
This is enough to see the problem:
CRS: NA
First 5 geometries:
MULTIPOLYGON (((-11103211 3540951, -11102945 35...
MULTIPOLYGON (((-10981244 3470857, -10981233 34...
The CRS is "NA"...
5
votes
Accepted
Export list of shapely.geometry.polygons as Esri shapefile
You can easily save them to a shapefile using geopandas.
import geopandas as gpd
from shapely.geometry import Polygon
# polygons sample
polygons = [Polygon([(0, 0), (1, 1), (1, 0)]),
...
5
votes
Accepted
Download shapefiles from arcgis.com
If you're using ogr2ogr you can just read the data directly, no need to export to shapefile and risk messing up the field names because of the shapefile (dbf) limitations.
Based on the examples in the ...
5
votes
Accepted
Creating polygon that should not move when panning the map QGIS
Building this in QGIS won't help when it comes to GeoServer's WMS, you need to look at the WMS Decorators that GeoServer provides for this. I think the text decorator should do most of what you want.
5
votes
Creating polygon that should not move when panning the map QGIS
Solution: Geometry Generator
You can use Geometry Generator to create the boxes, based on the variable @map_extent that generates a polygon representing the current extent of the map canvas. Form the ...
5
votes
Accepted
Keeping background (zero values) transparent while converting array to shapefile with Python
If you use rasterio.features.shapes instead of dataset_features you don't need to create a dataset, you can just use your numpy array and a transform.
In the example below I've used a donut shaped ...
4
votes
Accepted
Auto-generate Grid Reference for feature centroid & add to attributes, QGIS
I wrote a custom function get_osgb36 which retrieves the geometry's centroid and computes the Ordnance Survey Grid code (or returns "Out of bounds").
It requires one argument, the precision; ...
4
votes
KMZ to shapefile
You can use the "KML Tools" plugin, it has the option "expand HTML Description Field", with it you can recover existing fields in KMZ/KML, for example, those that appear in Google ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
shapefile × 5545qgis × 1651
arcgis-desktop × 652
python × 612
r × 419
coordinate-system × 353
polygon × 316
raster × 276
postgis × 253
arcmap × 252
gdal × 252
convert × 239
arcpy × 209
ogr2ogr × 199
data × 177
csv × 165
ogr × 163
geojson × 147
pyqgis × 145
geopandas × 141
attribute-table × 138
kml × 136
vector × 133
export × 126
fields-attributes × 122