c# - Arcs/vertices to MultiPolygon -


i have list of arcs (vertices) in form:

public class arc {     public guid id { get; set; }     public double x1 { get; set; }     public double y1 { get; set; }     public double x2 { get; set; }     public double y2 { get; set; } } 

which can serialize multilinestring geojson in case of 2 arcs:

{ "type": "multilinestring",     "coordinates": [     [ [100.0, 0.0], [101.0, 1.0] ],     [ [102.0, 2.0], [103.0, 3.0] ]     ] } 

my underlying data represent polygons. more precisely multipolygon:

{ "type": "multipolygon",     "coordinates": [       [[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],       [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],        [[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]]       ]     } 

just curious, possible transform original arcs multipolygon? thinking doing via sql server's gis functionalities. did ever encounter similar problem? pointers appreciated. many thanks.

ps:

the arcs disjoint , when combined should form closed polygon. following picture shows part of potential polygon.

enter image description here

here go. present huge caveat wrote iteratively , if came across else in production code, i'd have talk them. :)

declare @g geography = geography::stgeomfromtext('multilinestring((100 0, 101 1), (102 2, 103 3))', 4236); declare @multipoly geography;  cte (     select *     dbo.numbers n     cross apply (         select *         (values              (@g.stgeometryn(number).ststartpoint().lat, @g.stgeometryn(number).ststartpoint().long, 1),             (@g.stgeometryn(number).stendpoint().lat, @g.stgeometryn(number).ststartpoint().long, 2),             (@g.stgeometryn(number).stendpoint().lat, @g.stgeometryn(number).stendpoint().long, 3),             (@g.stgeometryn(number).ststartpoint().lat, @g.stgeometryn(number).stendpoint().long, 4),             (@g.stgeometryn(number).ststartpoint().lat, @g.stgeometryn(number).ststartpoint().long, 5)         ) x(lat, long, n)     ) decomp     n.number <= @g.stnumgeometries() ) select @multipoly = geography::stgeomfromtext(     'multipolygon (' + stuff((         select ', ((' + stuff((             select ', ' + cast(cte.long varchar(10)) + ' ' + cast(cte.lat varchar(10))             cte             number = n.number             order cte.n             xml path('')         ), 1, 2, '') + '))'         dbo.numbers n         n.number <= @g.stnumgeometries()         xml path('')         ), 1, 2, '') + ')'     , 4236);   select @multipoly; 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -