How to segment polygon in to line segment?Where is my Polygon?Line vs. Polygon Intersection CoordinatesMulti-part Geometrical Intersection errorSpatial join with multiple intersecting featuresPython buffer points and clip with line-segment (OS Open Roads in BNG)Using SET methods when feature classes setup in GDB using python, comtypes, ArcObjects?Calculating Total Line Length of a Network with Shapely: AssertionErrorConvert multiple polylines to polygons in QGISHow to divide polyline layer using shared vertexOverlay two linestring objects in geopandas, accounting for the attributes

Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)

Which country benefited the most from UN Security Council vetoes?

How to move a thin line with the black arrow in Illustrator?

Arrow those variables!

Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?

Roll the carpet

What defenses are there against being summoned by the Gate spell?

Does object always see its latest internal state irrespective of thread?

Approximately how much travel time was saved by the opening of the Suez Canal in 1869?

Can a monk's single staff be considered dual wielded, as per the Dual Wielder feat?

When a company launches a new product do they "come out" with a new product or do they "come up" with a new product?

Mortgage Pre-approval / Loan - Apply Alone or with Fiancée?

How old can references or sources in a thesis be?

Why is 150k or 200k jobs considered good when there's 300k+ births a month?

How to determine what difficulty is right for the game?

Could an aircraft fly or hover using only jets of compressed air?

How is it possible to have an ability score that is less than 3?

Client team has low performances and low technical skills: we always fix their work and now they stop collaborate with us. How to solve?

If human space travel is limited by the G force vulnerability, is there a way to counter G forces?

High voltage LED indicator 40-1000 VDC without additional power supply

Why does Kotter return in Welcome Back Kotter?

"You are your self first supporter", a more proper way to say it

Watching something be written to a file live with tail

DC-DC converter from low voltage at high current, to high voltage at low current



How to segment polygon in to line segment?


Where is my Polygon?Line vs. Polygon Intersection CoordinatesMulti-part Geometrical Intersection errorSpatial join with multiple intersecting featuresPython buffer points and clip with line-segment (OS Open Roads in BNG)Using SET methods when feature classes setup in GDB using python, comtypes, ArcObjects?Calculating Total Line Length of a Network with Shapely: AssertionErrorConvert multiple polylines to polygons in QGISHow to divide polyline layer using shared vertexOverlay two linestring objects in geopandas, accounting for the attributes






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I want to segment a Polygon or PolyLine in segment of line and remove some segments. I have an polygon that i convert in polyline by the code below and it work well:



from shapely.geometry import mapping, LineString
import fiona as fn
import operator
from functools import reduce

with fn.open('multipolygon.shp', 'r') as source:
source.profile['schema']['geometry'] = 'LineString'
with fn.open('segment_line.shp', 'w', **source.meta) as sink:
for feat in source:
xcoords_poly = feat['geometry']['coordinates']
liste_coords = reduce(operator.concat, xcoords_poly)
lines = LineString(liste_coords)
assert lines.is_valid
assert lines.geom_type == 'LineString'
feat['geometry'] = mapping(lines)
sink.write(feat)


After this step i want to remove some segments (lines) of my polyline where they overlays with some polygons as this picture show it :
enter image description here



For doing that i make the code below :



# great function that i find here to get coords of geometry
def pair(list):
'''Iterate over pairs in a list -> pair of points '''
for i in range(1, len(list)):
yield list[i-1], list[i]

to_del = []
fn_obs = fn.open('obs.shp')
with fn.open('segment_line.shp', 'r') as source:
with fn.open('avoid_obstacle.shp', 'w', **source.meta) as sink:
for f in source:
geom_f = shape(f['geometry'])
try:
for ob in fn_obs:
xob = shape(ob['geometry'])
if(geom_f.intersects(xob)):
to_keep = []

for seg_start, seg_end in pair(geom_f.coords):
line_start = Point(seg_start)
line_end = Point(seg_end)
segment = LineString([line_start.coords[0], line_end.coords[0]])
if(segment.intersects(xob)):
to_del.append(segment)
else:
to_keep.append(segment)
new_seg = linemerge(to_keep)
f['geometry'] = mapping(new_seg)
sink.write(f)

except (Exception):
logging.exception("Error type of file:", f)


And i got this results :
Result i got



It's like good but what i want it to remove all the line as this picture show it :enter image description here










share|improve this question






























    1















    I want to segment a Polygon or PolyLine in segment of line and remove some segments. I have an polygon that i convert in polyline by the code below and it work well:



    from shapely.geometry import mapping, LineString
    import fiona as fn
    import operator
    from functools import reduce

    with fn.open('multipolygon.shp', 'r') as source:
    source.profile['schema']['geometry'] = 'LineString'
    with fn.open('segment_line.shp', 'w', **source.meta) as sink:
    for feat in source:
    xcoords_poly = feat['geometry']['coordinates']
    liste_coords = reduce(operator.concat, xcoords_poly)
    lines = LineString(liste_coords)
    assert lines.is_valid
    assert lines.geom_type == 'LineString'
    feat['geometry'] = mapping(lines)
    sink.write(feat)


    After this step i want to remove some segments (lines) of my polyline where they overlays with some polygons as this picture show it :
    enter image description here



    For doing that i make the code below :



    # great function that i find here to get coords of geometry
    def pair(list):
    '''Iterate over pairs in a list -> pair of points '''
    for i in range(1, len(list)):
    yield list[i-1], list[i]

    to_del = []
    fn_obs = fn.open('obs.shp')
    with fn.open('segment_line.shp', 'r') as source:
    with fn.open('avoid_obstacle.shp', 'w', **source.meta) as sink:
    for f in source:
    geom_f = shape(f['geometry'])
    try:
    for ob in fn_obs:
    xob = shape(ob['geometry'])
    if(geom_f.intersects(xob)):
    to_keep = []

    for seg_start, seg_end in pair(geom_f.coords):
    line_start = Point(seg_start)
    line_end = Point(seg_end)
    segment = LineString([line_start.coords[0], line_end.coords[0]])
    if(segment.intersects(xob)):
    to_del.append(segment)
    else:
    to_keep.append(segment)
    new_seg = linemerge(to_keep)
    f['geometry'] = mapping(new_seg)
    sink.write(f)

    except (Exception):
    logging.exception("Error type of file:", f)


    And i got this results :
    Result i got



    It's like good but what i want it to remove all the line as this picture show it :enter image description here










    share|improve this question


























      1












      1








      1








      I want to segment a Polygon or PolyLine in segment of line and remove some segments. I have an polygon that i convert in polyline by the code below and it work well:



      from shapely.geometry import mapping, LineString
      import fiona as fn
      import operator
      from functools import reduce

      with fn.open('multipolygon.shp', 'r') as source:
      source.profile['schema']['geometry'] = 'LineString'
      with fn.open('segment_line.shp', 'w', **source.meta) as sink:
      for feat in source:
      xcoords_poly = feat['geometry']['coordinates']
      liste_coords = reduce(operator.concat, xcoords_poly)
      lines = LineString(liste_coords)
      assert lines.is_valid
      assert lines.geom_type == 'LineString'
      feat['geometry'] = mapping(lines)
      sink.write(feat)


      After this step i want to remove some segments (lines) of my polyline where they overlays with some polygons as this picture show it :
      enter image description here



      For doing that i make the code below :



      # great function that i find here to get coords of geometry
      def pair(list):
      '''Iterate over pairs in a list -> pair of points '''
      for i in range(1, len(list)):
      yield list[i-1], list[i]

      to_del = []
      fn_obs = fn.open('obs.shp')
      with fn.open('segment_line.shp', 'r') as source:
      with fn.open('avoid_obstacle.shp', 'w', **source.meta) as sink:
      for f in source:
      geom_f = shape(f['geometry'])
      try:
      for ob in fn_obs:
      xob = shape(ob['geometry'])
      if(geom_f.intersects(xob)):
      to_keep = []

      for seg_start, seg_end in pair(geom_f.coords):
      line_start = Point(seg_start)
      line_end = Point(seg_end)
      segment = LineString([line_start.coords[0], line_end.coords[0]])
      if(segment.intersects(xob)):
      to_del.append(segment)
      else:
      to_keep.append(segment)
      new_seg = linemerge(to_keep)
      f['geometry'] = mapping(new_seg)
      sink.write(f)

      except (Exception):
      logging.exception("Error type of file:", f)


      And i got this results :
      Result i got



      It's like good but what i want it to remove all the line as this picture show it :enter image description here










      share|improve this question
















      I want to segment a Polygon or PolyLine in segment of line and remove some segments. I have an polygon that i convert in polyline by the code below and it work well:



      from shapely.geometry import mapping, LineString
      import fiona as fn
      import operator
      from functools import reduce

      with fn.open('multipolygon.shp', 'r') as source:
      source.profile['schema']['geometry'] = 'LineString'
      with fn.open('segment_line.shp', 'w', **source.meta) as sink:
      for feat in source:
      xcoords_poly = feat['geometry']['coordinates']
      liste_coords = reduce(operator.concat, xcoords_poly)
      lines = LineString(liste_coords)
      assert lines.is_valid
      assert lines.geom_type == 'LineString'
      feat['geometry'] = mapping(lines)
      sink.write(feat)


      After this step i want to remove some segments (lines) of my polyline where they overlays with some polygons as this picture show it :
      enter image description here



      For doing that i make the code below :



      # great function that i find here to get coords of geometry
      def pair(list):
      '''Iterate over pairs in a list -> pair of points '''
      for i in range(1, len(list)):
      yield list[i-1], list[i]

      to_del = []
      fn_obs = fn.open('obs.shp')
      with fn.open('segment_line.shp', 'r') as source:
      with fn.open('avoid_obstacle.shp', 'w', **source.meta) as sink:
      for f in source:
      geom_f = shape(f['geometry'])
      try:
      for ob in fn_obs:
      xob = shape(ob['geometry'])
      if(geom_f.intersects(xob)):
      to_keep = []

      for seg_start, seg_end in pair(geom_f.coords):
      line_start = Point(seg_start)
      line_end = Point(seg_end)
      segment = LineString([line_start.coords[0], line_end.coords[0]])
      if(segment.intersects(xob)):
      to_del.append(segment)
      else:
      to_keep.append(segment)
      new_seg = linemerge(to_keep)
      f['geometry'] = mapping(new_seg)
      sink.write(f)

      except (Exception):
      logging.exception("Error type of file:", f)


      And i got this results :
      Result i got



      It's like good but what i want it to remove all the line as this picture show it :enter image description here







      python shapely fiona






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 2 at 15:48









      gene

      37.5k156120




      37.5k156120










      asked Apr 2 at 10:40









      EliteElite

      182




      182




















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "79"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f317471%2fhow-to-segment-polygon-in-to-line-segment%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f317471%2fhow-to-segment-polygon-in-to-line-segment%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          រឿង រ៉ូមេអូ និង ហ្ស៊ុយលីយេ សង្ខេបរឿង តួអង្គ បញ្ជីណែនាំ

          QGIS export composer to PDF scale the map [closed] Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Print Composer QGIS 2.6, how to export image?QGIS 2.8.1 print composer won't export all OpenCycleMap base layer tilesSave Print/Map QGIS composer view as PNG/PDF using Python (without changing anything in visible layout)?Export QGIS Print Composer PDF with searchable text labelsQGIS Print Composer does not change from landscape to portrait orientation?How can I avoid map size and scale changes in print composer?Fuzzy PDF export in QGIS running on macSierra OSExport the legend into its 100% size using Print ComposerScale-dependent rendering in QGIS PDF output

          PDF-ში გადმოწერა სანავიგაციო მენიუproject page