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;
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 :
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 :
It's like good but what i want it to remove all the line as this picture show it :
python shapely fiona
add a comment |
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 :
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 :
It's like good but what i want it to remove all the line as this picture show it :
python shapely fiona
add a comment |
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 :
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 :
It's like good but what i want it to remove all the line as this picture show it :
python shapely fiona
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 :
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 :
It's like good but what i want it to remove all the line as this picture show it :
python shapely fiona
python shapely fiona
edited Apr 2 at 15:48
gene
37.5k156120
37.5k156120
asked Apr 2 at 10:40
EliteElite
182
182
add a comment |
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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