예제 #1
0
bool ShpReader::SetupVectorProjection(OGRDataSource* OGRDataset, StudyControllerPtr studyController, OGRLayer* poLayer, VectorMapControllerPtr vectorMapController)
{
	//If there exists a map layer, the vector file will be projected based on the projection of the map layer
	if ( App::Inst().GetLayerTreeController()->GetNumMapLayers() > 0 )
	{
		ProjectionToolPtr projTool = studyController->GetProjectionTool();
		OGRSpatialReference* currentShpSR = poLayer->GetSpatialRef();
		if (!studyController->IsProjectData() && !studyController->IsGeographic())
		{
			needProjection=false;			
			Log::Inst().Write("The projection information for this study is being ignored.");
		}
		else
		{
	
			if(currentShpSR != NULL) 
			{
				if(currentShpSR->IsGeographic())
				{
					Log::Inst().Write("Loading vector map with geographic coordinates.");
					studyController->SetProjectData(true);
					studyController->SetGeographic(true);
					needProjection=true;
					poTransform = studyController->GetProjectionTool();
				}
				else if(currentShpSR->IsProjected())
				{
					studyController->SetProjectData(true);
					studyController->SetGeographic(false);
					needProjection=true;
					Log::Inst().Write("Loading vector map with projected coordinates.");
					ProjectionToolPtr projTool = studyController->GetProjectionTool();
					//OGRSpatialReference* currentLatLong = currentShpSR->CloneGeogCS();
					OGRSpatialReference *targetCS= projTool->GetTargetCS ();
					if(targetCS != NULL && !currentShpSR->IsSame(targetCS)) 
						poTransform.reset(OGRCreateCoordinateTransformation(currentShpSR, targetCS));
					
					else
						needProjection=false;

				}
				else
				{
				// The user should probably be made aware of this warning.
					Log::Inst().Warning("(Warning) Unknown type of coordinate system.");
					return false;
				}
			}		
	

			else 
			{
				//studyController->SetProjectData(false);
				//studyController->SetGeographic(false);
				needProjection=false;		
				
				Log::Inst().Write("Coordinate system information is not available for this map.");
				Log::Inst().Write("As a result, the projection information for this study is being ignored.");
				Log::Inst().Write("");
			
			}

		return true;
		}
	}
	// App::Inst().GetLayerTreeController()->GetNumMapLayers() ==0
	else
	{
		OGRSpatialReference* currentShpSR = poLayer->GetSpatialRef();
	//OGRSpatialReference oSource;
		if(currentShpSR != NULL) 
		{
			if(currentShpSR->IsGeographic())
			{
			// lat/lon coordinates are using the geographic projection (aka, plate carrée) 
				Log::Inst().Write("Loading vector map with lat/long coordinates.");
				studyController->SetProjectData(true);
				studyController->SetGeographic(true);
				needProjection=true;

			// determine centre of map
				VectorMapModelPtr vectorMapModel = vectorMapController->GetVectorMapModel();
				float vectorMinX= vectorMapModel->GetVectorBoundary_MinX();
				float vectorMinY = vectorMapModel->GetVectorBoundary_MinY();
				float vectorMaxX = vectorMapModel->GetVectorBoundary_MaxX();
				float vectorMaxY = vectorMapModel->GetVectorBoundary_MaxY();
			
				studyController->SetCentreLongitude(float(vectorMinX + fabs(vectorMinX - vectorMaxX) / 2.0));			
				studyController->SetCentreLatitude(float(vectorMinY + fabs(vectorMinY - vectorMaxY) / 2.0));

				studyController->SetFirstStandardParallel(vectorMinY);
				studyController->SetSecondStandardParallel(vectorMaxY);

				studyController->CalculateProjectionTool(currentShpSR);
				poTransform = studyController->GetProjectionTool();

			}
			else if(currentShpSR->IsProjected())
			{
				studyController->SetProjectData(true);
				studyController->SetGeographic(false);
				Log::Inst().Write("Loading vector map with projected coordinates.");
				studyController->CalculateProjectionTool(currentShpSR);
				poTransform = studyController->GetProjectionTool();
				needProjection=false;
			}
			else
			{
				// The user should probably be made aware of this warning.
				Log::Inst().Warning("(Warning) Unknown type of coordinate system.");
				return false;
				}
		}
		else 
		{
			studyController->SetProjectData(false);
			studyController->SetGeographic(false);
			needProjection=false;
		
			
			Log::Inst().Write("Coordinate system information is not available for this map.");
			Log::Inst().Write("As a result, the projection information for this study is being ignored.");
			Log::Inst().Write("To overlaid a Vector map on top of this map, the vector map must be specified in the same coordinate system as this map");
			Log::Inst().Write("");
		
		}
		}

	return true;
}
예제 #2
0
void ShpReader::VectorMetaDataInfo(OGRDataSource* OGRDataset, StudyControllerPtr studyController, VectorMapControllerPtr vectorMapController)
{	
	vFileMetaData* vHeader = vectorMapController->GetVectorMapModel()->GetVectorMetaData();
    OGRLayer *poLayer = OGRDataset->GetLayer( 0 );	
	char *originalWkt = NULL;	
	char *destinationWkt = NULL;

	OGREnvelope psEnvelope;
	poLayer->GetExtent( &psEnvelope );
	vHeader->originalExtents.x = psEnvelope.MinX;
	vHeader->originalExtents.dx = psEnvelope.MaxX;
	vHeader->originalExtents.y = psEnvelope.MinY; 
	vHeader->originalExtents.dy = psEnvelope.MaxY;
	Log::Inst().Write("Original Extents: ");
	Log::Inst().Write(_T("Lower, Left (x,y): ") +wxString(StringTools::ToStringW(vHeader->originalExtents.x, 2).c_str()) + _T(", ") 
		+ wxString(StringTools::ToStringW(vHeader->originalExtents.y, 2).c_str()));	
	Log::Inst().Write(_T("Upper, Right (x,y): ") +wxString(StringTools::ToStringW(vHeader->originalExtents.dx, 2).c_str()) + _T(", ") 
		+ wxString(StringTools::ToStringW(vHeader->originalExtents.dy, 2).c_str()));		

	vHeader->numFeatures= poLayer->GetFeatureCount();
	Log::Inst().Write("Number of Features: " + StringTools::ToString(vHeader->numFeatures));
	
	std::string type;
	OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
	if ( wkbFlatten( poFDefn->GetGeomType() ) == wkbPoint || wkbFlatten( poFDefn->GetGeomType() ) == wkbMultiPoint )
		 type="Point";
	else if ( wkbFlatten(poFDefn->GetGeomType() ) == wkbLineString || wkbFlatten(poFDefn->GetGeomType() ) == wkbMultiLineString )
		type="Polyline";
	else if ( wkbFlatten( poFDefn->GetGeomType() ) == wkbPolygon || wkbFlatten( poFDefn->GetGeomType() ) == wkbMultiPolygon )
		 type="Polygon";  	
	else
		type="Unknown";

	 vHeader->geometryType=type;
	 Log::Inst().Write("Geometry Type: "+ type);

	OGRSpatialReference* originalShpSR = poLayer->GetSpatialRef();	
	if (originalShpSR != NULL)
	{
		originalShpSR->exportToWkt(&originalWkt);	
		vHeader->originalProjection = std::string(originalWkt);
	}
	Log::Inst().Write("Original Projection: " + vHeader->originalProjection);
	Log::Inst().Write("");
	ProjectionToolPtr projTool = studyController->GetProjectionTool();
	if (projTool != NULL)
	{
		OGRSpatialReference *destinationCS= projTool->GetTargetCS ();
		destinationCS->exportToWkt(&destinationWkt);
		vHeader->destinationProjection = std::string(destinationWkt);
	}

	vHeader->currentExtents.x = vectorMapController->GetVectorMapModel()->GetVectorBoundary_MinX();
	vHeader->currentExtents.y = vectorMapController->GetVectorMapModel()->GetVectorBoundary_MinY();	

	vHeader->currentExtents.dx = vectorMapController->GetVectorMapModel()->GetVectorBoundary_MaxX();
	vHeader->currentExtents.dy = vectorMapController->GetVectorMapModel()->GetVectorBoundary_MaxY();
	//Log::Inst().Write("Upper, Right (x,y): " +
	//	StringTools::ToString(vHeader->currentExtents.dx) + ", " +
		//StringTools::ToString(vHeader->currentExtents.dy));
	
}