bool OgrUtilities::isReasonableUrl(const QString& url) { // Not a pretty way to sort out the /vsizip/ driver problem // We are searching for "/vsi" which will match /vsizip, /vsigzip, /vsitar, /vsicurl // I am not sure if matching this many things is a good idea. if (url.startsWith("/vsi")) { return true; } return getDriverInfo(url, true)._driverName != NULL; }
boost::shared_ptr<GDALDataset> OgrUtilities::openDataSource(const QString url, bool readonly) { /* Check for the correct driver name, if unknown try all drivers. * This can be an issue because drivers are tried in the order that they are * loaded which has been known to cause issues. */ OgrDriverInfo driverInfo = getDriverInfo(url, readonly); // With GDALOpenEx, we need to specify the GDAL_OF_UPDATE option or the dataset will get opened // Read Only. if (! readonly) { driverInfo._driverType = driverInfo._driverType | GDAL_OF_UPDATE; } LOG_VART(driverInfo._driverName); LOG_VART(driverInfo._driverType); LOG_VART(url.toUtf8().data()); const char* drivers[2] = { driverInfo._driverName, NULL }; // Setup read options for various file types OgrOptions options; if (QString(driverInfo._driverName) == "CSV") { options["X_POSSIBLE_NAMES"] = ConfigOptions().getOgrReaderCsvLonfield(); options["Y_POSSIBLE_NAMES"] = ConfigOptions().getOgrReaderCsvLatfield(); // options["Z_POSSIBLE_NAMES"] = ConfigOptions().getOgrReaderCsvZfield(); options["KEEP_GEOM_COLUMNS"] = ConfigOptions().getOgrReaderCsvKeepGeomFields(); } if (QString(driverInfo._driverName) == "OGR_OGDI") { // From the GDAL docs: // From GDAL/OGR 1.8.0, setting the OGR_OGDI_LAUNDER_LAYER_NAMES configuration option // (or environment variable) to YES causes the layer names to be simplified. // For example : watrcrsl_hydro instead of 'watrcrsl@hydro(*)_line' options["OGR_OGDI_LAUNDER_LAYER_NAMES"] = ConfigOptions().getOgrReaderOgdiLaunderLayerNames(); } boost::shared_ptr<GDALDataset> result(static_cast<GDALDataset*>(GDALOpenEx(url.toUtf8().data(), driverInfo._driverType, (driverInfo._driverName != NULL ? drivers : NULL), options.getCrypticOptions(), NULL))); if (!result) throw HootException("Unable to open: " + url); return result; }
boost::shared_ptr<GDALDataset> OgrUtilities::createDataSource(const QString& url) { QString source = url; OgrDriverInfo driverInfo = getDriverInfo(url, false); if (driverInfo._driverName == NULL) throw HootException("Error getting driver info for: " + url); GDALDriver *driver = GetGDALDriverManager()->GetDriverByName(driverInfo._driverName); if (driver == 0) throw HootException("Error getting driver by name: " + QString(driverInfo._driverName)); // if the user specifies a shapefile then crop off the .shp and create a directory. if (url.toLower().endsWith(".shp")) source = url.mid(0, url.length() - 4); boost::shared_ptr<GDALDataset> result(driver->Create(source.toAscii(), 0, 0, 0, GDT_Unknown, NULL)); if (result == NULL) { throw HootException("Unable to create data source: " + source + " (" + QString(CPLGetLastErrorMsg()) + ")"); } return result; }
void Telescope::registerProperty(INDI::Property *prop) { if (!strcmp(prop->getName(), "TELESCOPE_INFO")) { INumberVectorProperty *ti = prop->getNumber(); if (ti == NULL) return; bool aperture_ok=false, focal_ok=false; double temp=0; INumber *aperture = IUFindNumber(ti, "TELESCOPE_APERTURE"); if (aperture && aperture->value == 0) { if (getDriverInfo()->getAuxInfo().contains("TELESCOPE_APERTURE")) { temp = getDriverInfo()->getAuxInfo().value("TELESCOPE_APERTURE").toDouble(&aperture_ok); if (aperture_ok) { aperture->value = temp; INumber *g_aperture = IUFindNumber(ti, "GUIDER_APERTURE"); if (g_aperture && g_aperture->value == 0) g_aperture->value = aperture->value; } } } INumber *focal_length = IUFindNumber(ti, "TELESCOPE_FOCAL_LENGTH"); if (focal_length && focal_length->value == 0) { if (getDriverInfo()->getAuxInfo().contains("TELESCOPE_FOCAL_LENGTH")) { temp = getDriverInfo()->getAuxInfo().value("TELESCOPE_FOCAL_LENGTH").toDouble(&focal_ok); if (focal_ok) { focal_length->value = temp; INumber *g_focal = IUFindNumber(ti, "GUIDER_FOCAL_LENGTH"); if (g_focal && g_focal->value == 0) g_focal->value = focal_length->value; } } } if (aperture_ok && focal_ok) clientManager->sendNewNumber(ti); } if (!strcmp(prop->getName(), "TELESCOPE_PARK")) { ISwitchVectorProperty *svp = prop->getSwitch(); if (svp) { ISwitch *sp = IUFindSwitch(svp, "PARK"); if (sp) { IsParked = ( (sp->s == ISS_ON) && svp->s == IPS_OK); } } } DeviceDecorator::registerProperty(prop); }