Skip to content

Commit 34e3876

Browse files
committed
Merge branch 'develop' of https://github.com/sweco-sedahd/MapWinGIS into develop
2 parents c1c6aa6 + 2f4f3c1 commit 34e3876

3 files changed

Lines changed: 115 additions & 51 deletions

File tree

src/Ogr/OgrConverter.cpp

Lines changed: 103 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,35 @@ void AddPoints(CShape* shp, OGRLineString* geom, int startPointIndex, int endPoi
7171
{
7272
ShpfileType shpType;
7373
shp->get_ShapeType(&shpType);
74-
bool isM = ShapeUtility::IsM(shpType);
74+
bool haveZ = ShapeUtility::IsZ(shpType);
75+
bool haveM = ShapeUtility::HaveM(shpType);
7576

7677
VARIANT_BOOL vb;
77-
double x, y, z;
78+
double x, y, z, m;
7879
for( int i = startPointIndex; i < endPointIndex; i++ )
7980
{
80-
if (isM)
81+
if ( haveZ )
8182
{
82-
shp->get_XY(i, &x, &y, &vb);
83-
shp->get_M(i, &z);
83+
shp->get_XYZ(i, &x, &y, &z);
84+
if( haveM )
85+
{
86+
shp->get_M(i, &m);
87+
geom->addPoint(x, y, z, m);
88+
}
89+
else
90+
geom->addPoint(x, y, z);
8491
}
85-
else
92+
else // No Z
8693
{
87-
shp->get_XYZ(i, &x, &y, &z);
94+
shp->get_XY(i, &x, &y, &vb);
95+
if( haveM )
96+
{
97+
shp->get_M(i, &m);
98+
geom->addPointM(x, y, m);
99+
}
100+
else
101+
geom->addPoint(x, y);
88102
}
89-
geom->addPoint(x, y, z);
90103
}
91104
}
92105

@@ -106,12 +119,15 @@ OGRGeometry* OgrConverter::ShapeToGeometry(IShape* shape, OGRwkbGeometryType for
106119
long numPoints, numParts;
107120
long beg_part, end_part;
108121
ShpfileType shptype;
109-
double x,y,z;
122+
double x,y,z,m;
110123

111124
shp->get_ShapeType(&shptype);
112125
shp->get_NumParts(&numParts);
113126
shp->get_NumPoints(&numPoints);
114127

128+
bool haveZ = ShapeUtility::IsZ(shptype);
129+
bool haveM = ShapeUtility::HaveM(shptype);
130+
115131
VARIANT_BOOL vb;
116132

117133
if (shptype == SHP_POINT || shptype == SHP_POINTM || shptype == SHP_POINTZ)
@@ -120,18 +136,27 @@ OGRGeometry* OgrConverter::ShapeToGeometry(IShape* shape, OGRwkbGeometryType for
120136
OGRPoint *oPnt = (OGRPoint*)OGRGeometryFactory::createGeometry(wkbPoint);
121137
if (numPoints > 0)
122138
{
123-
if (shptype == SHP_POINTM)
139+
if ( haveZ )
124140
{
125-
shp->get_XY(0, &x, &y, &vb);
126-
shp->get_M(0, &z);
141+
shp->get_XYZ(0, &x, &y, &z);
142+
if( haveM )
143+
{
144+
shp->get_M(0, &m);
145+
oPnt->setM(m);
146+
}
147+
oPnt->setZ(z);
127148
}
128-
else
149+
else // No Z
129150
{
130-
shp->get_XYZ(0, &x, &y, &z);
151+
shp->get_XY(0, &x, &y, &vb);
152+
if( haveM )
153+
{
154+
shp->get_M(0, &m);
155+
oPnt->setM(m);
156+
}
131157
}
132158
oPnt->setX(x);
133159
oPnt->setY(y);
134-
oPnt->setZ(z);
135160
}
136161
oGeom = oPnt;
137162
}
@@ -144,19 +169,28 @@ OGRGeometry* OgrConverter::ShapeToGeometry(IShape* shape, OGRwkbGeometryType for
144169
{
145170
for( int i = 0; i < numPoints; i++ )
146171
{
147-
if (shptype == SHP_MULTIPOINTM)
172+
OGRPoint *oPnt = (OGRPoint*)OGRGeometryFactory::createGeometry(wkbPoint);
173+
if ( haveZ )
148174
{
149-
shp->get_XY(i, &x, &y, &vb);
150-
shp->get_M(i, &z);
175+
shp->get_XYZ(0, &x, &y, &z);
176+
oPnt->setZ(z);
177+
if( haveM )
178+
{
179+
shp->get_M(0, &m);
180+
oPnt->setM(m);
181+
}
151182
}
152-
else
183+
else // No Z
153184
{
154-
shp->get_XYZ(i, &x, &y, &z);
185+
shp->get_XY(0, &x, &y, &vb);
186+
if( haveM )
187+
{
188+
shp->get_M(0, &m);
189+
oPnt->setM(m);
190+
}
155191
}
156-
OGRPoint *oPnt = (OGRPoint*)OGRGeometryFactory::createGeometry(wkbPoint);
157192
oPnt->setX(x);
158193
oPnt->setY(y);
159-
oPnt->setZ(z);
160194
oMPnt->addGeometryDirectly(oPnt); // no memory release is needed when "direct" methods are used
161195
}
162196
}
@@ -412,32 +446,35 @@ IShape * OgrConverter::GeometryToShape(OGRGeometry* oGeom, bool isM,
412446
if (oForceType != wkbNone)
413447
oType = oForceType;
414448

415-
if (oType == wkbPoint || oType == wkbPoint25D || oType == wkbPointZM)
449+
if (oType == wkbPoint || oType == wkbPoint25D || oType == wkbPointM || oType == wkbPointZM)
416450
{
417451
if (oType == wkbPoint)
418452
shptype = SHP_POINT;
419-
else if (oType == wkbPoint25D || oType == wkbPointZM)
453+
else if (oType == wkbPoint25D || oType == wkbPointM || oType == wkbPointZM)
420454
shptype = isM ? SHP_POINTM : SHP_POINTZ;
421455

422456
OGRPoint* oPnt = (OGRPoint *) oGeom;
423457

424458
ComHelper::CreateShape(&shp);
425459
shp->put_ShapeType(shptype);
426460

461+
bool haveZ = shptype == SHP_POINTZ;
462+
bool haveM = shptype == SHP_POINTZ || shptype == SHP_POINTM;
463+
427464
ComHelper::CreatePoint(&pnt);
428465
pnt->put_X(oPnt->getX());
429466
pnt->put_Y(oPnt->getY());
430-
if (isM) pnt->put_M(oPnt->getZ());
431-
else pnt->put_Z(oPnt->getZ());
467+
if(haveZ) pnt->put_Z(oPnt->getZ());
468+
if(haveM) pnt->put_M(oPnt->getM());
432469
shp->InsertPoint(pnt,&pointIndex,&retval);
433470
pnt->Release();
434471
}
435472

436-
else if (oType == wkbMultiPoint || oType == wkbMultiPoint25D || oType == wkbMultiPointZM)
473+
else if (oType == wkbMultiPoint || oType == wkbMultiPoint25D || oType == wkbMultiPointM || oType == wkbMultiPointZM)
437474
{
438475
if (oType == wkbMultiPoint)
439476
shptype = SHP_MULTIPOINT;
440-
else if (oType == wkbMultiPoint25D || oType == wkbMultiPointZM)
477+
else if (oType == wkbMultiPoint25D || oType == wkbMultiPointM || oType == wkbMultiPointZM)
441478
shptype = isM ? SHP_MULTIPOINTM : SHP_MULTIPOINTZ;
442479

443480
OGRMultiPoint* oMPnt = (OGRMultiPoint* ) oGeom;
@@ -447,6 +484,9 @@ IShape * OgrConverter::GeometryToShape(OGRGeometry* oGeom, bool isM,
447484
ComHelper::CreateShape(&shp);
448485
shp->put_ShapeType(shptype);
449486

487+
bool haveZ = shptype == SHP_MULTIPOINTZ;
488+
bool haveM = shptype == SHP_MULTIPOINTZ || shptype == SHP_MULTIPOINTM;
489+
450490
for(long i = 0; i < oMPnt->getNumGeometries(); i++ )
451491
{
452492
OGRPoint* oPnt = (OGRPoint *) oMPnt->getGeometryRef(i);
@@ -457,20 +497,20 @@ IShape * OgrConverter::GeometryToShape(OGRGeometry* oGeom, bool isM,
457497
ComHelper::CreatePoint(&pnt);
458498
pnt->put_X(oPnt->getX());
459499
pnt->put_Y(oPnt->getY());
460-
if (isM) pnt->put_M(oPnt->getZ());
461-
else pnt->put_Z(oPnt->getZ());
500+
if(haveZ) pnt->put_Z(oPnt->getZ());
501+
if(haveM) pnt->put_M(oPnt->getM());
462502
shp->InsertPoint(pnt,&i,&retval);
463503
pnt->Release();
464504
}
465505
}
466506
}
467507
}
468508

469-
else if (oType == wkbLineString || oType == wkbLineString25D || oType == wkbLineStringZM)
509+
else if (oType == wkbLineString || oType == wkbLineString25D || oType == wkbLineStringM || oType == wkbLineStringZM)
470510
{
471511
if (oType == wkbLineString)
472512
shptype = SHP_POLYLINE;
473-
else if (oType == wkbLineString25D || oType == wkbLineStringZM)
513+
else if (oType == wkbLineString25D || oType == wkbLineStringM || oType == wkbLineStringZM)
474514
shptype = isM ? SHP_POLYLINEM : SHP_POLYLINEZ;
475515

476516
OGRLineString* oLine = (OGRLineString *) oGeom;
@@ -480,24 +520,27 @@ IShape * OgrConverter::GeometryToShape(OGRGeometry* oGeom, bool isM,
480520
ComHelper::CreateShape(&shp);
481521
shp->put_ShapeType(shptype);
482522
shp->InsertPart(0,&partIndex,&retval);
483-
523+
524+
bool haveZ = shptype == SHP_POLYLINEZ;
525+
bool haveM = shptype == SHP_POLYLINEZ || shptype == SHP_POLYLINEM;
526+
484527
for(long i = 0; i < oLine->getNumPoints(); i++ )
485528
{
486529
ComHelper::CreatePoint(&pnt);
487530
pnt->put_X(oLine->getX(i));
488531
pnt->put_Y(oLine->getY(i));
489-
if (isM) pnt->put_M(oLine->getZ(i));
490-
else pnt->put_Z(oLine->getZ(i));
532+
if(haveZ) pnt->put_Z(oLine->getZ(i));
533+
if(haveM) pnt->put_M(oLine->getM(i));
491534
shp->InsertPoint(pnt,&i,&retval);
492535
pnt->Release();
493536
}
494537
}
495538

496-
else if (oType == wkbMultiLineString || oType == wkbMultiLineString25D || oType == wkbMultiLineStringZM)
539+
else if (oType == wkbMultiLineString || oType == wkbMultiLineString25D || oType == wkbMultiLineStringM || oType == wkbMultiLineStringZM)
497540
{
498541
if (oType == wkbMultiLineString)
499542
shptype = SHP_POLYLINE;
500-
else if (oType == wkbMultiLineString25D || oType == wkbMultiLineStringZM)
543+
else if (oType == wkbMultiLineString25D || oType == wkbMultiLineStringM || oType == wkbMultiLineStringZM)
501544
shptype = isM ? SHP_POLYLINEM : SHP_POLYLINEZ;
502545

503546
OGRMultiLineString * oMLine = (OGRMultiLineString *) oGeom;
@@ -506,7 +549,10 @@ IShape * OgrConverter::GeometryToShape(OGRGeometry* oGeom, bool isM,
506549

507550
ComHelper::CreateShape(&shp);
508551
shp->put_ShapeType(shptype);
509-
552+
553+
bool haveZ = shptype == SHP_POLYLINEZ;
554+
bool haveM = shptype == SHP_POLYLINEZ || shptype == SHP_POLYLINEM;
555+
510556
long count = 0;
511557
for (long j=0; j < oMLine->getNumGeometries(); j++)
512558
{
@@ -524,8 +570,8 @@ IShape * OgrConverter::GeometryToShape(OGRGeometry* oGeom, bool isM,
524570
ComHelper::CreatePoint(&pnt);
525571
pnt->put_X(oLine->getX(i));
526572
pnt->put_Y(oLine->getY(i));
527-
if (isM) pnt->put_M(oLine->getZ(i));
528-
else pnt->put_Z(oLine->getZ(i));
573+
if(haveZ) pnt->put_Z(oLine->getZ(i));
574+
if(haveM) pnt->put_M(oLine->getM(i));
529575
shp->InsertPoint(pnt,&count,&retval);
530576
pnt->Release();
531577
if (retval) count++;
@@ -536,7 +582,7 @@ IShape * OgrConverter::GeometryToShape(OGRGeometry* oGeom, bool isM,
536582
}
537583

538584
// (meant to be part of poly; but we'll treat it alone also)
539-
else if (oType == wkbLinearRing)
585+
else if (oType == wkbLinearRing)
540586
{
541587
OGRLinearRing* oRing;
542588

@@ -552,31 +598,34 @@ IShape * OgrConverter::GeometryToShape(OGRGeometry* oGeom, bool isM,
552598
shp->put_ShapeType(shptype);
553599
shp->InsertPart(0,&partIndex,&retval);
554600

601+
bool haveZ = shptype == SHP_POLYGONZ;
602+
bool haveM = shptype == SHP_POLYGONZ || shptype == SHP_POLYGONM;
603+
555604
for(long i=0; i< oRing->getNumPoints(); i++)
556605
{
557606
ComHelper::CreatePoint(&pnt);
558607
pnt->put_X(oRing->getX(i));
559608
pnt->put_Y(oRing->getY(i));
560-
if (isM) pnt->put_M(oRing->getZ(i));
561-
else pnt->put_Z(oRing->getZ(i));
609+
if(haveZ) pnt->put_Z(oRing->getZ(i));
610+
if(haveM) pnt->put_M(oRing->getM(i));
562611
shp->InsertPoint(pnt,&i,&retval);
563612
pnt->Release();
564613
}
565614
}
566615

567-
else if (oType == wkbPolygon || oType == wkbPolygon25D || oType == wkbPolygonZM ||
616+
else if (oType == wkbPolygon || oType == wkbPolygon25D || oType == wkbPolygonM || oType == wkbPolygonZM ||
568617
oType == wkbMultiPolygon || oType == wkbMultiPolygon25D || oType == wkbMultiPolygonZM)
569618
{
570619
OGRPolygon* oPoly;
571620
OGRLinearRing** papoRings=NULL;
572621
int nRings = 0;
573622

574-
if ((oType == wkbPolygon25D || oType == wkbPolygonZM || oType == wkbMultiPolygon25D || oType == wkbMultiPolygonZM) || force25D)
623+
if ((oType == wkbPolygon25D || oType == wkbPolygonM || oType == wkbPolygonZM || oType == wkbMultiPolygon25D || oType == wkbMultiLineStringM || oType == wkbMultiPolygonZM) || force25D)
575624
shptype = isM ? SHP_POLYGONM : SHP_POLYGONZ;
576625
else if (oType == wkbPolygon || oType == wkbMultiPolygon)
577626
shptype = SHP_POLYGON;
578627

579-
if (oType == wkbPolygon || oType == wkbPolygon25D || oType == wkbPolygonZM)
628+
if (oType == wkbPolygon || oType == wkbPolygon25D || oType == wkbPolygonM || oType == wkbPolygonZM)
580629
{
581630
oPoly = (OGRPolygon *) oGeom;
582631

@@ -597,15 +646,15 @@ IShape * OgrConverter::GeometryToShape(OGRGeometry* oGeom, bool isM,
597646
}
598647
}
599648

600-
else if (oType == wkbMultiPolygon || oType == wkbMultiPolygon25D || oType == wkbMultiPolygonZM)
649+
else if (oType == wkbMultiPolygon || oType == wkbMultiPolygon25D || oType == wkbMultiPolygonM || oType == wkbMultiPolygonZM)
601650
{
602651
OGRMultiPolygon* oMPoly = (OGRMultiPolygon *) oGeom;
603652

604653
for(int iGeom=0; iGeom < oMPoly->getNumGeometries(); iGeom++ )
605654
{
606655
oPoly = (OGRPolygon *) oMPoly->getGeometryRef(iGeom);
607656

608-
if (oPoly->getGeometryType() == wkbPolygon || oPoly->getGeometryType() == wkbPolygon25D || oPoly->getGeometryType() == wkbPolygonZM)
657+
if (oPoly->getGeometryType() == wkbPolygon || oPoly->getGeometryType() == wkbPolygon25D || oPoly->getGeometryType() == wkbPolygonM || oPoly->getGeometryType() == wkbPolygonZM)
609658
{
610659
if( oPoly->getExteriorRing() == NULL) continue;
611660
if (oPoly->getExteriorRing()->IsEmpty()) continue;
@@ -631,7 +680,10 @@ IShape * OgrConverter::GeometryToShape(OGRGeometry* oGeom, bool isM,
631680

632681
ComHelper::CreateShape(&shp);
633682
shp->put_ShapeType(shptype);
634-
683+
684+
bool haveZ = shptype == SHP_POLYGONZ;
685+
bool haveM = shptype == SHP_POLYGONZ || shptype == SHP_POLYGONM;
686+
635687
OGRLinearRing *oRing;
636688
long count = 0;
637689

@@ -645,8 +697,8 @@ IShape * OgrConverter::GeometryToShape(OGRGeometry* oGeom, bool isM,
645697
ComHelper::CreatePoint(&pnt);
646698
pnt->put_X(oRing->getX(i));
647699
pnt->put_Y(oRing->getY(i));
648-
if (isM) pnt->put_M(oRing->getZ(i));
649-
else pnt->put_Z(oRing->getZ(i));
700+
if(haveZ) pnt->put_Z(oRing->getZ(i));
701+
if(haveM) pnt->put_M(oRing->getM(i));
650702
shp->InsertPoint(pnt,&count,&retval);
651703
pnt->Release();
652704
pnt = NULL;

src/Shapefile/ShapeUtility.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ bool ShapeUtility::IsZ(const ShpfileType shpType)
2828
|| shpType == SHP_POLYGONZ;
2929
}
3030

31+
// **************************************************************
32+
// HaveM()
33+
// **************************************************************
34+
bool ShapeUtility::HaveM(const ShpfileType shpType)
35+
{
36+
return shpType == SHP_POINTM || shpType == SHP_POINTZ
37+
|| shpType == SHP_MULTIPOINTM || shpType == SHP_MULTIPOINTZ
38+
|| shpType == SHP_POLYLINEM || shpType == SHP_POLYLINEZ
39+
|| shpType == SHP_POLYGONM || shpType == SHP_POLYGONZ;
40+
}
41+
3142
// **************************************************************
3243
// Convert2D()
3344
// **************************************************************

src/Shapefile/ShapeUtility.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class ShapeUtility
88
static void SwapEndian(char* a, int size);
99
static bool IsM(ShpfileType shpType);
1010
static bool IsZ(ShpfileType shpType);
11+
static bool HaveM(const ShpfileType shpType);
1112
static ShpfileType Convert2D(ShpfileType shpType);
1213
static ShpfileType Get25DShapeType(ShpfileType shpTypeBase, bool isZ, bool isM);
1314
static IShapeWrapper* CreateWrapper(char* data, int recordLength, bool forceCom);

0 commit comments

Comments
 (0)