Shapes displayed incorrectly using geoshow (Mapping Toolbox)

조회 수: 10 (최근 30일)
Idono
Idono 2018년 1월 30일
답변: Jyotish Robin 2018년 2월 8일
Hi,
I have some problems with the Mapping Toolbox (R2017a). I imported some shapes from OSM using shaperead and tried to display them using geoshow. While most of the shapes are displayed correctly, some of the shapes create a patch object, that fills the complete maps and hides every other object beneath it.
Example code for a corrupt and a working shape:
shape1.Geometry = 'Polygon';
shape1.BoundingBox = [11.0186 49.3611;11.0193 49.3614];
shape1.Lon = [11.0191817000000 11.0192651000000 11.0192897000000 11.0191317000000 11.0190105000000 11.0186397000000 11.0186004000000 11.0186320000000 11.0186516000000 11.0191817000000 NaN];
shape1.Lat = [49.3611009000000 49.3611440000000 49.3612309000000 49.3613649000000 49.3614104000000 49.3613958000000 49.3613354000000 49.3611160000000 49.3611021000000 49.3611009000000 NaN];
shape2.Geometry = 'Polygon';
shape2.BoundingBox = [11.1880 49.3695;11.1898 49.3707];
shape2.Lon = [11.1892892000000 11.1894704000000 11.1895831000000 11.1898330000000 11.1879680000000 11.1880448000000 11.1883267000000 11.1884480000000 11.1892892000000 NaN];
shape2.Lat = [49.3706881000000 49.3705091000000 49.3704724000000 49.3699670000000 49.3694895000000 49.3697801000000 49.3698850000000 49.3705595000000 49.3706881000000 NaN];
figure(1)
subplot(2,1,1)
title('Plot as struct (polygon)')
geoshow(shape1)
subplot(2,1,2)
geoshow(shape1.Lat,shape1.Lon)
title('Plot as coordinates (line)')
suptitle('Shape 1 - Corrupt')
figure(2)
subplot(2,1,1)
title('Plot as struct (polygon)')
geoshow(shape2)
subplot(2,1,2)
geoshow(shape2.Lat,shape2.Lon)
title('Plot as coordinates (line)')
suptitle('Shape 2 - Working')
Output:
Is this a bug? Does anyone know a solution/workaround?

답변 (1개)

Jyotish Robin
Jyotish Robin 2018년 2월 8일
Hi!
The problem is that the vertices in the shape are not clockwise. The vertices are defining a hole instead.
You can see that with the code below.
>> ispolycw(shape1.Lon, shape1.Lat)
ans =
logical
0
Here is a simple fix:
>> [lon,lat] = poly2cw(shape1.Lon, shape1.Lat);
>> shape1.Lon = lon;
>> shape1.Lat = lat;
>> geoshow(shape1)
Hope this helps!
Thanks,
Jyotish

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by