45 #include <ogrsf_frmts.h> 48 #ifdef CHECK_MEMORY_LEAKS 50 #endif // CHECK_MEMORY_LEAKS 59 if (!oc.
isSet(
"shapefile-prefixes")) {
63 std::vector<std::string> files = oc.
getStringVector(
"shapefile-prefixes");
64 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
66 load(*file, oc, toFill, tm);
79 std::string prefix = oc.
getString(
"prefix");
82 int layer = oc.
getInt(
"layer");
83 std::string idField = oc.
getString(
"shapefile.id-column");
84 bool useRunningID = oc.
getBool(
"shapefile.use-running-id");
86 std::string shpName = file +
".shp";
88 if (oc.
getString(
"shapefile.fill") ==
"true") {
90 }
else if (oc.
getString(
"shapefile.fill") ==
"false") {
93 #if GDAL_VERSION_MAJOR < 2 95 OGRDataSource* poDS = OGRSFDriverRegistrar::Open(shpName.c_str(), FALSE);
98 GDALDataset* poDS = (GDALDataset*) GDALOpen(shpName.c_str(), GA_ReadOnly);
101 throw ProcessError(
"Could not open shape description '" + shpName +
"'.");
105 OGRLayer* poLayer = poDS->GetLayer(0);
106 poLayer->ResetReading();
109 OGRSpatialReference* origTransf = poLayer->GetSpatialRef();
110 OGRSpatialReference destTransf;
112 destTransf.SetWellKnownGeogCS(
"WGS84");
113 OGRCoordinateTransformation* poCT = OGRCreateCoordinateTransformation(origTransf, &destTransf);
115 if (oc.
isSet(
"shapefile.guess-projection")) {
116 OGRSpatialReference origTransf2;
117 origTransf2.SetWellKnownGeogCS(
"WGS84");
118 poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf);
121 WRITE_WARNING(
"Could not create geocoordinates converter; check whether proj.4 is installed.");
125 OGRFeature* poFeature;
126 poLayer->ResetReading();
127 unsigned int runningID = 0;
128 while ((poFeature = poLayer->GetNextFeature()) != NULL) {
129 std::vector<Parameterised*> parCont;
131 std::string
id = useRunningID ?
toString(runningID) : poFeature->GetFieldAsString(idField.c_str());
135 throw ProcessError(
"Missing id under '" + idField +
"'");
139 OGRGeometry* poGeometry = poFeature->GetGeometryRef();
140 if (poGeometry == 0) {
141 OGRFeature::DestroyFeature(poFeature);
145 poGeometry->transform(poCT);
146 OGRwkbGeometryType gtype = poGeometry->getGeometryType();
149 OGRPoint* cgeom = (OGRPoint*) poGeometry;
152 WRITE_ERROR(
"Unable to project coordinates for POI '" +
id +
"'.");
155 if (toFill.
insert(
id, poi, layer)) {
156 parCont.push_back(poi);
160 case wkbLineString: {
161 bool fill = fillType < 0 ?
false : (fillType == 1);
162 OGRLineString* cgeom = (OGRLineString*) poGeometry;
164 for (
int j = 0; j < cgeom->getNumPoints(); j++) {
167 WRITE_ERROR(
"Unable to project coordinates for polygon '" +
id +
"'.");
172 if (toFill.
insert(
id, poly, layer)) {
173 parCont.push_back(poly);
178 bool fill = fillType < 0 ?
true : (fillType == 1);
179 OGRLinearRing* cgeom = ((OGRPolygon*) poGeometry)->getExteriorRing();
181 for (
int j = 0; j < cgeom->getNumPoints(); j++) {
184 WRITE_ERROR(
"Unable to project coordinates for polygon '" +
id +
"'.");
189 if (toFill.
insert(
id, poly, layer)) {
190 parCont.push_back(poly);
194 case wkbMultiPoint: {
195 OGRMultiPoint* cgeom = (OGRMultiPoint*) poGeometry;
196 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
197 OGRPoint* cgeom2 = (OGRPoint*) cgeom->getGeometryRef(i);
199 std::string tid =
id +
"#" +
toString(i);
201 WRITE_ERROR(
"Unable to project coordinates for POI '" + tid +
"'.");
204 if (toFill.
insert(tid, poi, layer)) {
205 parCont.push_back(poi);
210 case wkbMultiLineString: {
211 bool fill = fillType < 0 ?
false : (fillType == 1);
212 OGRMultiLineString* cgeom = (OGRMultiLineString*) poGeometry;
213 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
214 OGRLineString* cgeom2 = (OGRLineString*) cgeom->getGeometryRef(i);
216 std::string tid =
id +
"#" +
toString(i);
217 for (
int j = 0; j < cgeom2->getNumPoints(); j++) {
220 WRITE_ERROR(
"Unable to project coordinates for polygon '" + tid +
"'.");
225 if (toFill.
insert(tid, poly, layer)) {
226 parCont.push_back(poly);
231 case wkbMultiPolygon: {
232 bool fill = fillType < 0 ?
true : (fillType == 1);
233 OGRMultiPolygon* cgeom = (OGRMultiPolygon*) poGeometry;
234 for (
int i = 0; i < cgeom->getNumGeometries(); ++i) {
235 OGRLinearRing* cgeom2 = ((OGRPolygon*) cgeom->getGeometryRef(i))->getExteriorRing();
237 std::string tid =
id +
"#" +
toString(i);
238 for (
int j = 0; j < cgeom2->getNumPoints(); j++) {
241 WRITE_ERROR(
"Unable to project coordinates for polygon '" + tid +
"'.");
246 if (toFill.
insert(tid, poly, layer)) {
247 parCont.push_back(poly);
253 WRITE_WARNING(
"Unsupported shape type occured (id='" +
id +
"').");
256 if (oc.
getBool(
"shapefile.add-param")) {
257 for (std::vector<Parameterised*>::const_iterator it = parCont.begin(); it != parCont.end(); ++it) {
258 OGRFeatureDefn* poFDefn = poLayer->GetLayerDefn();
259 for (
int iField = 0; iField < poFDefn->GetFieldCount(); iField++) {
260 OGRFieldDefn* poFieldDefn = poFDefn->GetFieldDefn(iField);
261 if (poFieldDefn->GetNameRef() != idField) {
262 if (poFieldDefn->GetType() == OFTReal) {
263 (*it)->addParameter(poFieldDefn->GetNameRef(),
toString(poFeature->GetFieldAsDouble(iField)));
271 OGRFeature::DestroyFeature(poFeature);
275 WRITE_ERROR(
"SUMO was compiled without GDAL support.");
std::vector< std::string > getStringVector(const std::string &name) const
Returns the list of string-vector-value of the named option (only for Option_String) ...
static RGBColor parseColor(std::string coldef)
Parses a color information.
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
bool x2cartesian(Position &from, bool includeInBoundary=true)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
bool insert(const std::string &id, Polygon *poly, int layer, bool ignorePruning=false)
Adds a polygon to the storage.
#define WRITE_WARNING(msg)
A storage for loaded polygons and pois.
static std::string latin1_to_utf8(std::string str)
Transfers from Latin 1 (ISO-8859-1) to UTF-8.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
A storage for type mappings.
static methods for processing the coordinates conversion for the current net
A point in 2D or 3D with translation and scaling methods.
static void loadIfSet(OptionsCont &oc, PCPolyContainer &toFill, PCTypeMap &tm)
Loads pois/polygons assumed to be stored as shape files-files.
static void load(const std::string &file, OptionsCont &oc, PCPolyContainer &toFill, PCTypeMap &tm)
Parses pois/polys stored within the given file.
#define PROGRESS_BEGIN_MESSAGE(msg)
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
static std::string prune(const std::string &str)
Removes trailing and leading whitechars.
A storage for options typed value containers)
void push_back_noDoublePos(const Position &p)
#define PROGRESS_DONE_MESSAGE()
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.