View Full Version : Reproject a shapefile

06-24-2013, 07:23 AM
I am using the maps package and haven't been able to find a way to get what I want to work. In the samples directory there is a sample (projimg) that will project an image (earth.jpg) in whatever projection you select and there is another sample (shapefile) that will read a shapefile and display it in its native projection. I need to be able to read in a shapefile as a collection of IlvMapFeatures which are in an IlvGeographicProjection and display them in either their native projection, in an IlvOrthographicProjection or in an IlvMercatorProjection. I am attempting to read a shapefile (obtained from www.naturalearthdata.com/downloads/50m-physical-vectors) which contains the oceans and overlay the data on a world map which can be displayed in any of the operator selectable projections listed above. Any help on how to do this using the maps package would be greatly appreciated.

06-24-2013, 08:19 AM
Hello Ken,
Overall, to do so the process is:
- Empty the manager (deleteAll)
- Create the new projection
- Create a new MapInfo, replace the one attached to the manager, and possibly destroy the old one
- Reload the data
- Refresh the view

Hope this helps,

06-25-2013, 11:22 AM
Thanks Claude, This seems to be what I'm doing but I'm still only getting the shapes to appear in the one projection, Geographic. When the other projections are selected the oceans layer appears blank. The following is extracted from my code. Maybe something obvious will jump out at you that will explain why it's not working:

void MapManager::showProjection(IlvProjection *projectionPtr)
myManagerPtr->deleteAll(IlTrue, IlFalse); // myManagerPtr is a pointer to an IlvManager
myProjectionPtr = projectionPtr;
IlvMapInfo *mapInfoPtr = new IlvMapInfo(projectionPtr, 0, IlFalse);

// In here a bunch of other layers are reprojected such as grid lines, country borders,
// the earth.jpg image and they all seem to come out fine




void MMsrvMapManger::loadOceanData()
const char *fileNameWithPathPtr = <file that contains the oceans shape data>;
IlvMapInfo *mapInfoPtr = new IlvMapInfo(myProjectionPtr, 0, IlTrue);

IlvMapLoader *mapLoaderPtr = new IlvMapLoader(myManagerPtr);
IlvGeographicProjection *geoProjPtr = new IlvGeographicProjection();

IlvMapFeatureIterator *featureIter = mapLoaderPtr->makeFeatureIterator(fileNameWithPathPtr);
if (featureIter)
IlvGraphic *graphic;

IlvFeatureRenderer *renderer = featureIter->getDefaultFeatureRenderer(myDisplayPtr);
// Does some stuff here to set Area and Line rendering styles

IlvMapsError status = IlvMaps::NoError();
for (const IlvMapFeature *f = featureIter->getNextFeature(status);
status == IlvMaps::NoError() && f;
f = featureIter->getNextFeature(status))
graphic = renderer->makeGraphic(*f, mapInfoPtr, status);
if (status == IlvMaps::NoError())
myManagerPtr->addObject(graphic, IlvFalse, <Ocean layer>);

myManagerPtr->fitTransformerToContents(myViewPtr, IlvTrue, IlvTrue);