Results 1 to 3 of 3

Thread: Reproject a shapefile

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    2

    Reproject a shapefile

    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 http://www.naturalearthdata.com/down...ysical-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.

  2. #2
    Junior Member
    Join Date
    Oct 2012
    Posts
    29
    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,
    Claude

  3. #3
    Junior Member
    Join Date
    Jun 2013
    Posts
    2
    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);
    mapInfoPtr->attach(myManagerPtr);

    // 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

    loadOceanData();

    showAll();

    }

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

    IlvMapLoader *mapLoaderPtr = new IlvMapLoader(myManagerPtr);
    IlvGeographicProjection *geoProjPtr = new IlvGeographicProjection();
    mapLoaderPtr->setDefaultSourceProjection(geoProjPtr);

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

    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->invalidateRegion(graphic);
    }
    }
    IlvSetContentsChangedUpdate(IlTrue);
    myManagerPtr->reDrawViews();

    myManagerPtr->fitTransformerToContents(myViewPtr, IlvTrue, IlvTrue);
    }
    }
    Last edited by Ken__; 07-03-2013 at 05:09 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •