void SuperMapConnection::CreateSpatialContext( FdoString* name, FdoString* description, FdoString* coordinateSystem, FdoString* coordinateSystemWkt, FdoSpatialContextExtentType extentType, FdoByteArray * extent, double xyTolerance, double zTolerance, bool update ) { bool found = false; // 检查是否有同一个WKT空间语义存在 for(FdoInt32 i = 0; i < m_SpatialContextColl->GetCount() && !found; ++i) { FdoPtr<SuperMapSpatialContext> sp = m_SpatialContextColl->GetItem(i); found = (coordinateSystemWkt == sp->GetCoordinateSystemWkt()); } // 赋新的坐标系 if(!found) { FdoPtr<SuperMapSpatialContext> newSp = new SuperMapSpatialContext(); FdoInt32 idxGenName = 1; FdoStringP newName = name; // 查找重复的空间语义名,在名字后加数字避免重名 while(m_SpatialContextColl->FindItem(newName)) { newName = FdoStringP::Format(L"%ls_%d", (FdoString*)name, idxGenName); idxGenName++; } //设置新的空间语义 newSp->SetName(newName); newSp->SetCoordSysName(coordinateSystem); newSp->SetCoordinateSystemWkt(coordinateSystemWkt); newSp->SetDescription(description); newSp->SetExtent(extent); newSp->SetExtentType(extentType); newSp->SetXYTolerance(xyTolerance); newSp->SetZTolerance(zTolerance); m_SpatialContextColl->Add(newSp); //Todo: 往物理数据源中添加投影信息是否在此做? } }
void FdoRfpSpatialContextCollection::ReadXml(FdoXmlReader* reader) { FdoXmlSpatialContextReaderP spreader = FdoXmlSpatialContextReader::Create(reader); // Read the one and ond supported spatial context while (spreader->ReadNext()) { FdoPtr<FdoRfpSpatialContext> context = new FdoRfpSpatialContext(); context->SetName(spreader->GetName()); context->SetDescription(spreader->GetDescription()); context->SetCoordinateSystem(spreader->GetCoordinateSystem()); context->SetCoordinateSystemWkt(spreader->GetCoordinateSystemWkt()); context->SetExtent(spreader->GetExtent()); context->SetExtentType(spreader->GetExtentType()); context->SetXYTolerance(spreader->GetXYTolerance()); context->SetZTolerance(spreader->GetZTolerance()); Add(context); } }
SuperMapSpatialContextCollection* SuperMapConnection::GetSpatialContexts() { TRACE(_T("开始调用 SuperMapConnection::GetSpatialContexts() 。\n")); if(m_SpatialContextColl == NULL) { // 通过物理数据源初始化空间语义列表 FdoStringP strName; FdoStringP strDescription; FdoStringP strCoordSysName; UGC::EmSpatialRefType eType; // 空间语义类型 FdoStringP strDatumName ; // 基准面名 DATUM FdoStringP strSpheroidName ; // 椭球体名 double dSemiMajor; // 椭球体长半轴长度 double dInvflattening; // 椭球体扁率倒数 FdoStringP strPrimeMeridian ; // 本初子午线(0度经线)通常为"Greenwich" FdoStringP GeoUnit ; // 地理单位 FdoStringP GeoUnitFactor ; // 地理单位换算系数 FdoStringP Unit ; // 单位 FdoStringP UnitFactor ; // 单位换算系数 FdoPtr<SuperMapSpatialContext> pSpatialContext = new SuperMapSpatialContext(); // 经纬度坐标和投影坐标都要取的公共参数 UGC::UGPrjCoordSys prjCoordSys = GetDataSource()->GetPrjCoordSys(); strName = prjCoordSys.GetName(); eType = prjCoordSys.GetSpatialRefType(); UGC::UGGeoCoordSys geoCoordSys = prjCoordSys.GetGeoCoordSys(); // 获取地理坐标信息 strCoordSysName = geoCoordSys.GetName(); UGC::UGHorizonDatum datum = geoCoordSys.GetHorizonDatum(); // 获取基准面信息 strDatumName = datum.GetDatumName(); UGC::UGSpheroid spheroid = datum.GetSpheroid(); // 获取椭球体信息 strSpheroidName = spheroid.GetName(); dSemiMajor = spheroid.GetAxis(); dInvflattening = 1/(spheroid.GetFlatten()); UGC::UGPrimeMeridian prmMeridian = geoCoordSys.GetPrimeMeridian(); // 获取本初子午线信息 strPrimeMeridian = prmMeridian.GetName(); // 获取地理单位和地理单位系数 switch(geoCoordSys.GetUnit()) { // 角度单位换算到弧度单位 case AU_DEGREE: GeoUnit = L"Degree"; GeoUnitFactor = L"0.01745329"; break; case AU_RADIAN: GeoUnit = L"Radian"; GeoUnitFactor = L"1.00000000"; break; case AU_MINUTE: GeoUnit = L"Minute"; GeoUnitFactor = L"0.00029089"; break; case AU_SECOND: GeoUnit = L"Second"; GeoUnitFactor = L"0.00000485"; break; case AU_GRAD: GeoUnit = L"Gard"; GeoUnitFactor = L"0.01570796"; break; case AU_MICRORADIAN: GeoUnit = L"MicroRadian"; GeoUnitFactor = L"0.00000100"; break; case AU_MINUTE_CENTESIMAL: GeoUnit = L"Minute_Centesimal"; GeoUnitFactor = L"0.00015708"; break; case AU_SECOND_CENTESIMAL: GeoUnit = L"Second_Centesimal"; GeoUnitFactor = L"0.00000157"; break; case AU_MIL_6400: GeoUnit = L"Mil_6400"; GeoUnitFactor = L"0.00098175"; break; } // 投影坐标单位 switch(prjCoordSys.GetUnit()) { // 长度单位换算到米 case AU_MM: Unit = L"MILLIMETER"; UnitFactor = L"0.001"; break; case AU_CM: Unit = L"CENTIMETER"; UnitFactor = L"0.01"; break; case AU_DM: Unit = L"DECIMETER"; UnitFactor = L"0.10"; break; case AU_M: Unit = L"METER"; UnitFactor = L"1.0"; break; case AU_KM: Unit = L"KILOMETER"; UnitFactor = L"1000.00"; break; case AU_MI: Unit = L"MILE"; UnitFactor = L"1609.31"; break; case AU_IN: Unit = L"INCH"; UnitFactor = L"0.0254"; break; case AU_YARD: Unit = L"YARD"; UnitFactor = L"0.9144"; break; case AU_FT: Unit = L"FOOT"; UnitFactor = L"0.3048"; break; default: Unit = L""; UnitFactor = L""; } if(eType == UGC::SPATIALREF_EARTH_PROJECTION) // 如果是投影坐标系,获取相关投影参数。 { UGC::UGProjection projection = prjCoordSys.GetProjection(); pSpatialContext->m_ProjectName = projection.GetProjectionName(); UGC::UGPrjParams prjParams = prjCoordSys.GetPrjParams(); //需要赋值的投影参数: //double m_dFalseEasting; // 0 False easting (X0) //double m_dFalseNorthing; // 1 False northing (Y0) //double m_dCentralMeridian; // 2 Central meridian, Longitude of origin (LON0) //double m_dCentralParallel; // 6 Central parallel, Latitude of origin (LAT0) //double m_dStandardParallel1; // 3 Standard parallel 1, Latitude of 1st point (LAT1) //double m_dStandardParallel2; // 4 Standard parallel 2, Latitude of 2nd point (LAT2) //double m_dScaleFactor; // 5 Scale factor //double m_dAzimuth; // 7 Azimuth //double m_dFirstPointLongitude; // 8 Longitude of 1st point (LON1) //double m_dSecondPointLongitude; // 9 Longitude of 2nd point (LON2) pSpatialContext->m_dFalseEasting = prjParams.m_dFalseEasting; pSpatialContext->m_dFalseNorthing = prjParams.m_dFalseNorthing; pSpatialContext->m_dCentralMeridian = prjParams.m_dCentralMeridian; pSpatialContext->m_dCentralParallel = prjParams.m_dCentralParallel; pSpatialContext->m_dStandardParallel1 = prjParams.m_dStandardParallel1; pSpatialContext->m_dStandardParallel2 = prjParams.m_dStandardParallel2; pSpatialContext->m_dScaleFactor = prjParams.m_dScaleFactor; pSpatialContext->m_dAzimuth = prjParams.m_dAzimuth; pSpatialContext->m_dFirstPointLongitude = prjParams.m_dFirstPointLongitude; pSpatialContext->m_dSecondPointLongitude = prjParams.m_dSecondPointLongitude; } // end for 取空间语义的实际值 // 设置公共的空间语义的参数 pSpatialContext->SetName(strName); pSpatialContext->SetDescription(strDescription); pSpatialContext->SetCoordSysName(strCoordSysName); //(strCoordSysName.Right(L"---")); pSpatialContext->m_eType = eType; pSpatialContext->m_DatumName = strDatumName; pSpatialContext->m_SpheroidName = strSpheroidName; pSpatialContext->m_dSemiMajor = dSemiMajor; pSpatialContext->m_dInvflattening = dInvflattening; pSpatialContext->m_PrimeMeridian = strPrimeMeridian; pSpatialContext->m_Unit = Unit; pSpatialContext->m_UnitFactor = UnitFactor; pSpatialContext->m_GeoUnit = GeoUnit; pSpatialContext->m_GeoUnitFactor = GeoUnitFactor; m_SpatialContextColl = new SuperMapSpatialContextCollection(); m_SpatialContextColl->Add(pSpatialContext); } return FDO_SAFE_ADDREF(m_SpatialContextColl.p); }