#include <PCLoaderArcView.h>
The current importer works only if SUMO was compiled with GDAL-support. If not, an error message is generated.
Definition at line 56 of file PCLoaderArcView.h.
Static Public Member Functions | |
| static void | loadIfSet (OptionsCont &oc, PCPolyContainer &toFill, PCTypeMap &tm) throw (ProcessError) |
| Loads pois/polygons assumed to be stored as shape files-files. | |
Static Protected Member Functions | |
| static void | load (const std::string &file, OptionsCont &oc, PCPolyContainer &toFill, PCTypeMap &tm) throw (ProcessError) |
| Parses pois/polys stored within the given file. | |
Private Member Functions | |
| PCLoaderArcView & | operator= (const PCLoaderArcView &) |
| Invalidated assignment operator. | |
| PCLoaderArcView (const PCLoaderArcView &) | |
| Invalidated copy constructor. | |
| PCLoaderArcView::PCLoaderArcView | ( | const PCLoaderArcView & | ) | [private] |
Invalidated copy constructor.
| void PCLoaderArcView::load | ( | const std::string & | file, | |
| OptionsCont & | oc, | |||
| PCPolyContainer & | toFill, | |||
| PCTypeMap & | tm | |||
| ) | throw (ProcessError) [static, protected] |
Parses pois/polys stored within the given file.
| [in] | oc | The options container to get further options from |
| [in] | toFill | The poly/pois container to add loaded polys/pois to |
| [in] | tm | The type map to use for setting values of loaded polys/pois |
| ProcessError | if something fails |
Definition at line 71 of file PCLoaderArcView.cpp.
References MsgHandler::endProcessMsg(), MsgHandler::getErrorInstance(), OptionsCont::getInt(), MsgHandler::getMessageInstance(), OptionsCont::getString(), MsgHandler::getWarningInstance(), MsgHandler::inform(), PCPolyContainer::insert(), OptionsCont::isSet(), RGBColor::parseColor(), StringUtils::prune(), Position2DVector::push_back_noDoublePos(), SUMOReal, toString(), WRITE_WARNING, and GeoConvHelper::x2cartesian().
00072 { 00073 #ifdef HAVE_GDAL 00074 // get defaults 00075 std::string prefix = oc.getString("prefix"); 00076 std::string type = oc.getString("type"); 00077 RGBColor color = RGBColor::parseColor(oc.getString("color")); 00078 int layer = oc.getInt("layer"); 00079 std::string idField = oc.getString("shape-files.id-name"); 00080 // start parsing 00081 std::string shpName = file + ".shp"; 00082 OGRRegisterAll(); 00083 OGRDataSource *poDS = OGRSFDriverRegistrar::Open(shpName.c_str(), FALSE); 00084 if (poDS == NULL) { 00085 throw ProcessError("Could not open shape description '" + shpName + "'."); 00086 } 00087 00088 // begin file parsing 00089 OGRLayer *poLayer = poDS->GetLayer(0); 00090 poLayer->ResetReading(); 00091 00092 // build coordinate transformation 00093 OGRSpatialReference *origTransf = poLayer->GetSpatialRef(); 00094 OGRSpatialReference destTransf; 00095 // use wgs84 as destination 00096 destTransf.SetWellKnownGeogCS("WGS84"); 00097 OGRCoordinateTransformation *poCT = OGRCreateCoordinateTransformation(origTransf, &destTransf); 00098 if (poCT == NULL) { 00099 if (oc.isSet("arcview.guess-projection")) { 00100 OGRSpatialReference origTransf2; 00101 origTransf2.SetWellKnownGeogCS("WGS84"); 00102 poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf); 00103 } 00104 if (poCT==0) { 00105 WRITE_WARNING("Could not create geocoordinates converter; check whether proj.4 is installed."); 00106 } 00107 } 00108 00109 OGRFeature *poFeature; 00110 poLayer->ResetReading(); 00111 while ((poFeature = poLayer->GetNextFeature()) != NULL) { 00112 // read in edge attributes 00113 std::string id = poFeature->GetFieldAsString(idField.c_str()); 00114 id = StringUtils::prune(id); 00115 if (id=="") { 00116 throw ProcessError("Missing id under '" + idField + "'"); 00117 } 00118 id = prefix + id; 00119 // read in the geometry 00120 OGRGeometry *poGeometry = poFeature->GetGeometryRef(); 00121 if (poGeometry!=0) { 00122 // try transform to wgs84 00123 poGeometry->transform(poCT); 00124 } 00125 OGRwkbGeometryType gtype = poGeometry->getGeometryType(); 00126 switch (gtype) { 00127 case wkbPoint: { 00128 OGRPoint *cgeom = (OGRPoint*) poGeometry; 00129 Position2D pos((SUMOReal) cgeom->getX(), (SUMOReal) cgeom->getY()); 00130 if (!GeoConvHelper::x2cartesian(pos)) { 00131 MsgHandler::getErrorInstance()->inform("Unable to project coordinates for POI '" + id + "'."); 00132 } 00133 PointOfInterest *poi = new PointOfInterest(id, type, pos, color); 00134 if (!toFill.insert(id, poi, layer)) { 00135 MsgHandler::getErrorInstance()->inform("POI '" + id + "' could not been added."); 00136 delete poi; 00137 } 00138 } 00139 break; 00140 case wkbLineString: { 00141 OGRLineString *cgeom = (OGRLineString*) poGeometry; 00142 Position2DVector shape; 00143 for (int j=0; j<cgeom->getNumPoints(); j++) { 00144 Position2D pos((SUMOReal) cgeom->getX(j), (SUMOReal) cgeom->getY(j)); 00145 if (!GeoConvHelper::x2cartesian(pos)) { 00146 MsgHandler::getErrorInstance()->inform("Unable to project coordinates for polygon '" + id + "'."); 00147 } 00148 shape.push_back_noDoublePos(pos); 00149 } 00150 Polygon2D *poly = new Polygon2D(id, type, color, shape, false); 00151 if (!toFill.insert(id, poly, layer)) { 00152 MsgHandler::getErrorInstance()->inform("Polygon '" + id + "' could not been added."); 00153 delete poly; 00154 } 00155 } 00156 break; 00157 case wkbPolygon: { 00158 OGRLinearRing *cgeom = ((OGRPolygon*) poGeometry)->getExteriorRing(); 00159 Position2DVector shape; 00160 for (int j=0; j<cgeom->getNumPoints(); j++) { 00161 Position2D pos((SUMOReal) cgeom->getX(j), (SUMOReal) cgeom->getY(j)); 00162 if (!GeoConvHelper::x2cartesian(pos)) { 00163 MsgHandler::getErrorInstance()->inform("Unable to project coordinates for polygon '" + id + "'."); 00164 } 00165 shape.push_back_noDoublePos(pos); 00166 } 00167 Polygon2D *poly = new Polygon2D(id, type, color, shape, true); 00168 if (!toFill.insert(id, poly, layer)) { 00169 MsgHandler::getErrorInstance()->inform("Polygon '" + id + "' could not been added."); 00170 delete poly; 00171 } 00172 } 00173 break; 00174 case wkbMultiPoint: { 00175 OGRMultiPoint *cgeom = (OGRMultiPoint*) poGeometry; 00176 for (int i=0; i<cgeom->getNumGeometries(); ++i) { 00177 OGRPoint *cgeom2 = (OGRPoint*) cgeom->getGeometryRef(i); 00178 Position2D pos((SUMOReal) cgeom2->getX(), (SUMOReal) cgeom2->getY()); 00179 std::string tid = id + "#" + toString(i); 00180 if (!GeoConvHelper::x2cartesian(pos)) { 00181 MsgHandler::getErrorInstance()->inform("Unable to project coordinates for POI '" + tid + "'."); 00182 } 00183 PointOfInterest *poi = new PointOfInterest(tid, type, pos, color); 00184 if (!toFill.insert(tid, poi, layer)) { 00185 MsgHandler::getErrorInstance()->inform("POI '" + tid + "' could not been added."); 00186 delete poi; 00187 } 00188 } 00189 } 00190 break; 00191 case wkbMultiLineString: { 00192 OGRMultiLineString *cgeom = (OGRMultiLineString*) poGeometry; 00193 for (int i=0; i<cgeom->getNumGeometries(); ++i) { 00194 OGRLineString *cgeom2 = (OGRLineString*) cgeom->getGeometryRef(i); 00195 Position2DVector shape; 00196 std::string tid = id + "#" + toString(i); 00197 for (int j=0; j<cgeom2->getNumPoints(); j++) { 00198 Position2D pos((SUMOReal) cgeom2->getX(j), (SUMOReal) cgeom2->getY(j)); 00199 if (!GeoConvHelper::x2cartesian(pos)) { 00200 MsgHandler::getErrorInstance()->inform("Unable to project coordinates for polygon '" + tid + "'."); 00201 } 00202 shape.push_back_noDoublePos(pos); 00203 } 00204 Polygon2D *poly = new Polygon2D(tid, type, color, shape, false); 00205 if (!toFill.insert(tid, poly, layer)) { 00206 MsgHandler::getErrorInstance()->inform("Polygon '" + tid + "' could not been added."); 00207 delete poly; 00208 } 00209 } 00210 } 00211 break; 00212 case wkbMultiPolygon: { 00213 OGRMultiPolygon *cgeom = (OGRMultiPolygon*) poGeometry; 00214 for (int i=0; i<cgeom->getNumGeometries(); ++i) { 00215 OGRLinearRing *cgeom2 = ((OGRPolygon*) cgeom->getGeometryRef(i))->getExteriorRing(); 00216 Position2DVector shape; 00217 std::string tid = id + "#" + toString(i); 00218 for (int j=0; j<cgeom2->getNumPoints(); j++) { 00219 Position2D pos((SUMOReal) cgeom2->getX(j), (SUMOReal) cgeom2->getY(j)); 00220 if (!GeoConvHelper::x2cartesian(pos)) { 00221 MsgHandler::getErrorInstance()->inform("Unable to project coordinates for polygon '" + tid + "'."); 00222 } 00223 shape.push_back_noDoublePos(pos); 00224 } 00225 Polygon2D *poly = new Polygon2D(tid, type, color, shape, true); 00226 if (!toFill.insert(tid, poly, layer)) { 00227 MsgHandler::getErrorInstance()->inform("Polygon '" + tid + "' could not been added."); 00228 delete poly; 00229 } 00230 } 00231 } 00232 break; 00233 default: 00234 MsgHandler::getWarningInstance()->inform("Unsupported shape type occured (id='" + id + "')."); 00235 break; 00236 } 00237 OGRFeature::DestroyFeature(poFeature); 00238 } 00239 MsgHandler::getMessageInstance()->endProcessMsg("done."); 00240 #else 00241 MsgHandler::getErrorInstance()->inform("SUMO was compiled without GDAL support."); 00242 #endif 00243 }
| void PCLoaderArcView::loadIfSet | ( | OptionsCont & | oc, | |
| PCPolyContainer & | toFill, | |||
| PCTypeMap & | tm | |||
| ) | throw (ProcessError) [static] |
Loads pois/polygons assumed to be stored as shape files-files.
If the option "shape-files" is set within the given options container, the files stored herein are parsed using "load", assuming this option contains file paths to files containing pois and polygons stored as shape-files.
| [in] | oc | The options container to get further options from |
| [in] | toFill | The poly/pois container to add loaded polys/pois to |
| [in] | tm | The type map to use for setting values of loaded polys/pois |
| ProcessError | if something fails |
Definition at line 54 of file PCLoaderArcView.cpp.
References MsgHandler::beginProcessMsg(), MsgHandler::endProcessMsg(), MsgHandler::getMessageInstance(), and load().
Referenced by main().
00055 { 00056 if (!oc.isSet("shape-files")) { 00057 return; 00058 } 00059 // parse file(s) 00060 std::vector<std::string> files = oc.getStringVector("shape-files"); 00061 for (std::vector<std::string>::const_iterator file=files.begin(); file!=files.end(); ++file) { 00062 MsgHandler::getMessageInstance()->beginProcessMsg("Parsing from shape-file '" + *file + "'..."); 00063 load(*file, oc, toFill, tm); 00064 MsgHandler::getMessageInstance()->endProcessMsg("done."); 00065 } 00066 }
| PCLoaderArcView& PCLoaderArcView::operator= | ( | const PCLoaderArcView & | ) | [private] |
Invalidated assignment operator.
1.5.6