Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm doing a spatial query, but I always get an error:

"msPOSTGISLayerGetShape(): Query error. msPOSTGISLayerGetShape called on unopened layer (layerinfo = NULL)"

This is my code:

layerObj layerUtbs = Util.MSMap.getLayerByName("Utbs");
if (layerUtbs.queryByRect(Util.MSMap, rect) == (int)MS_RETURN_VALUE.MS_SUCCESS)
    resultCacheObj resultado = layerUtbs.getResults();

    if (resultado.numresults > 0)
        // here i got a error.
        layerUtbs.getFeature(resultado.getResult(0).shapeindex, resultado.getResult(0).tileindex);

Here's my map file configuration

        CONNECTIONTYPE postgis 
        NAME "Utbs" 
        CONNECTION "user=pmc dbname=SiteInovacao host=localhost password=123 port=5432"
        DATA "geom from (SELECT *, oid FROM pmc.utbs) as utbs using unique oid using srid=31983"



share|improve this question
up vote 1 down vote accepted

Its basically telling you whats wrong- you have not 'opened' the layer Try this:

if (resultado.numresults > 0)
                // Open layer

                // here i got a error (you shouldn't now);.
                layerUtbs.getFeature(resultado.getResult(0).shapeindex, resultado.getResult(0).tileindex);
share|improve this answer
This is exactly what i want!! Thank you very much!! – Michel Andrade Jul 6 '11 at 12:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.