2

I have a map consisting of polygons and a line. I need to a new shapefile of polygons that are to the west of the red line, and are between the northmost and the southmost ends of the line. How can I do it in QGIS?

enter image description here

  • How do you define "between the northmost and southmost ends of the line"? Straight east - west or perpendicular to the line ends? – phloem Feb 3 '15 at 16:03
  • Straight east-west of the line ends. Thanks. – Anna Feb 3 '15 at 16:04
2

OK, this might not be the most elegant way to solve this, but it will work, and if you will only do it once you might as well go with this approach.

First of all, create a polygon (the button should be on the left side):

enter image description here

For this example you would have to enter absolutely no details, except for the coordinate system (CRS). Make sure it uses the same one that your other files use. Then you can hit OK, and you will be asked where to save the new shapefile. Save it, and then add it to your project.

enter image description here

Then you start the editing mode for that polygon (and make sure to enable snapping, so the polygon can snap to the endpoints of your line when digitizing, which means you have to check vertex, and then specify a tolerance of something like 5 pixels!):

enter image description here

enter image description here

Then you select both the polygon, and the line. And then you use the following tool from Digitizing Tools, to split both into two separate polyons:

enter image description here

Now you will have two different polygons, and you can discard the one on the right (just select it, and delete it), which leaves you with the area you are interested in (i.e. West of the line):

enter image description here

Then all you have to do is select by location. All the points that fall into that polygons, that is:

enter image description here

And at the very end you will export these to a new shapefile (or whatever vector you are using). You could also invert the selection and just delete all the other points.



PS: Not all the points on the west side have been included in my example, but I hope the approach makes sense; you'd just have to digitize your initial polygon differently.

  • Very useful and clear answer, brilliant! – Joseph Feb 3 '15 at 16:16
  • Thanks! It's very useful. I quick question: how do you create the initial polygon? By clicking "Select Features by Polygon, and then just making sure the polygon touches both ends of the line? – Anna Feb 3 '15 at 16:30
  • I have edited my post to address that as well. Let me know if you have more questions. – BritishSteel Feb 3 '15 at 17:01
  • 1
    Glad I could help! If it solved the question please mark my post as the answer. – BritishSteel Feb 3 '15 at 19:16
1

I know this isn't exactly what you're after, but this is how you can do it in ArcGIS (10.1+) with arcpy.

myPoly = [] # polygon container
dist = 10000 # east-west distance
with arcpy.da.SearchCursor("line",['SHAPE@']) as cursor:
     for row in cursor:
         # get new polygon coordinates
         feature_info = [[  [row[0].firstPoint.X-dist,row[0].firstPoint.Y],
                            [row[0].lastPoint.X-dist,row[0].lastPoint.Y],
                            [row[0].lastPoint.X+dist,row[0].lastPoint.Y],
                            [row[0].firstPoint.X+dist,row[0].firstPoint.Y] ]]
# create new polygon
myPoly.append(arcpy.Polygon(arcpy.Array([arcpy.Point(*coords) for coords in feature_info])))
# persist polygon
arcpy.CopyFeatures_management(myPoly,'in_memory\poly')

This creates the polygon you're after (straight east-west from line endpoints). Then, it's a matter of splitting the polygon into the part you want, and selecting the points.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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