3

I have a global dataset of earthquakes, I want to do some buffering around them. Having the earthquake dataset in the layer "query" and having a polygonlayer called "jordskjelvbuffer", I ran the following script:

quakelayer = 'query'
bufferlayer = 'jordskjelvbuffer'
bufferdist=100
quakes = QgsProject.instance().mapLayersByName(quakelayer)[0]
layer = QgsProject.instance().mapLayersByName(bufferlayer)[0]
feature = QgsFeature()
pnt=QgsGeometry.fromPointXY(QgsPointXY(0,0))
provider = layer.dataProvider()
layer.startEditing()
outcrs=QgsCoordinateReferenceSystem("EPSG:4326")
for quake in quakes.getFeatures():
    buffer=pnt.buffer(bufferdist*1000,5)
    geom = quake.geometry()
    point = geom.asPoint()
    lat = point.y()
    lon = point.x()
    projstring = f"PROJ:+proj=aeqd +lat_0={lat} +lon_0={lon}"
    crs = QgsCoordinateReferenceSystem(projstring)
    xform = QgsCoordinateTransform(crs,outcrs,QgsProject.instance())
    buffer.transform(xform)
    feature.setGeometry(buffer)
    provider.addFeatures( [feature] )
layer.commitChanges()

This is making a circle bufferdist * 1000 meters at 0,0 in a orthographic projection centered at each point and then reprojecting that circle into WGS84 before adding it to my buffer data set. (https://gis.stackexchange.com/a/49390/10123 suggested the projection to use)

This works well, except for those points in which the buffer is crossing the antimeridian at 180 degrees. In which case the buffers will "wrap around" over my map. How can I avoid this? enter image description here

Is it possible to tell the visualisation to do what I want or is there some way of splitting the buffers along the antimeridian?

1 Answer 1

3

I have managed to use your script and end-up with two part circles for those which overlap the 180 longitude line.

The way I did it:

  • Create your buffer layer

  • Reproject it to EPSG:3832 ("Reprojected" layer in my screenshot)

  • Create a layer(4326) with a line at 180 deg longitude

  • Reproject that line to EPSG:3832

  • Buffer that line (still in 3832) as a "BufferedLine" layer. Buffering width should be wide enough to be sure that it spans across the 180 line

  • Set the current rendering CRS to 3832 to have a clearer view, you should see the circles across the antimeridian, visually split by the buffered line: enter image description here

  • Apply a Difference transformation (Input: Reprojected, Overlay: BufferedLine, set the Input options to "Do not filter" for Invalid Features if you have errors. This should split the cirle in two parts that don't overlap the 180 longitude line. I don't know why, at first it did not work, the circle was not split, I had to try again.

  • Resulting "Difference" layer should show fine in EPSG:4326.

  • You can reproject "Difference" to EPSG:4326

Eastern side, faulty geometry in green, new half geometry in grey: enter image description here

Western side: enter image description here

Full view without the inappropriate geometry: enter image description here

I hope this works for your whole dataset

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.