-
Notifications
You must be signed in to change notification settings - Fork 66
/
shprewind.c
81 lines (69 loc) · 2.57 KB
/
shprewind.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/******************************************************************************
*
* Project: Shapelib
* Purpose: Utility to validate and reset the winding order of rings in
* polygon geometries to match the ordering required by spec.
* Author: Frank Warmerdam, [email protected]
*
******************************************************************************
* Copyright (c) 2002, Frank Warmerdam
*
* SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
******************************************************************************
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "shapefil.h"
int main(int argc, char **argv)
{
/* -------------------------------------------------------------------- */
/* Display a usage message. */
/* -------------------------------------------------------------------- */
if (argc != 3)
{
printf("shprewind in_shp_file out_shp_file\n");
exit(1);
}
/* -------------------------------------------------------------------- */
/* Open the passed shapefile. */
/* -------------------------------------------------------------------- */
SHPHandle hSHP = SHPOpen(argv[1], "rb");
if (hSHP == NULL)
{
printf("Unable to open:%s\n", argv[1]);
exit(1);
}
int nShapeType;
int nEntities;
double adfMinBound[4];
double adfMaxBound[4];
SHPGetInfo(hSHP, &nEntities, &nShapeType, adfMinBound, adfMaxBound);
/* -------------------------------------------------------------------- */
/* Create output shapefile. */
/* -------------------------------------------------------------------- */
SHPHandle hSHPOut = SHPCreate(argv[2], nShapeType);
if (hSHPOut == NULL)
{
SHPClose(hSHP);
printf("Unable to create:%s\n", argv[2]);
exit(1);
}
/* -------------------------------------------------------------------- */
/* Skim over the list of shapes, printing all the vertices. */
/* -------------------------------------------------------------------- */
int nInvalidCount = 0;
for (int i = 0; i < nEntities; i++)
{
SHPObject *psShape = SHPReadObject(hSHP, i);
if (SHPRewindObject(hSHP, psShape))
nInvalidCount++;
SHPWriteObject(hSHPOut, -1, psShape);
SHPDestroyObject(psShape);
}
SHPClose(hSHP);
SHPClose(hSHPOut);
printf("%d objects rewound.\n", nInvalidCount);
exit(0);
}