[Geomoose-users] Search based on lat/lon layer

Brent Fraser bfraser at geoanalytic.com
Mon Apr 27 14:38:48 EDT 2009


Jim (and others),

  My fix was to add a little bit of code to htdocs\lib\libs\Views.js (or the "compiled" GeoMoose.js), specifically to the convertViewString function around line 68:

function convertViewString(viewString, viewSize){
    viewString=viewString.replace(' ','');
    var viewSplit=viewString.split(',');

    if( window.fromLatLong && (Math.abs(viewSplit[1])<=90) && (Math.abs(viewSplit[0])<=180) ){
        var ptLonLat=new Point(viewSplit[0],viewSplit[1]);
        var ptXY=window.fromLatLong("",ptLonLat);
        var xyViewString=ptXY.x+","+ptXY.y+",";
        ptLonLat=new Point(viewSplit[2],viewSplit[3]);
        ptXY=window.fromLatLong("",ptLonLat);
        xyViewString=xyViewString+ptXY.x+","+ptXY.y;
        viewString=xyViewString;
    }

    var psArr=new Array();
		:

The if statement above checks to see if the layer's coords are geographic, then converts them to projected coords, and re-forms the viewString bounding box with the projected coords.  Because of the if statement any projected layers will work as before.

Best Regards,
Brent Fraser


Brent Fraser wrote:
> Jim,
> 
>  Regarding [shpmidx], etc (http://trac.osgeo.org/mapserver/ticket/2961); I did read it, but it doesn't apply here since an extent is needed (I want the entire polygon on the view), not just the centroid.  
>  I think your patch on [shpext] (http://trac.osgeo.org/mapserver/ticket/2894) is the fix for this problem.
> 
> Brent
> 
> Jim Klassen wrote:
>> Did you see/read/try Steve's comment in the trac entry?
>>
>>>>> Brent Fraser <bfraser at geoanalytic.com> 04/27/09 10:10 AM >>>
>> Jim,
>>
>>   Looks like your patch will do the trick for the future.  I'm trying to use a "stock" mapserver for this implementation (v5.2.1 from MS4W), and stay off the GeoMoose v2.0 Beta (with OpenLayers) bleeding edge, so I'll likely enhance the GeoMoose javas
> cript...
>> Thanks!
>> Brent
>>
>> Jim Klassen wrote:
>>> Two thoughts.
>>>
>>> 1) There have been recent changes to shpext and some of the other related tags in mapserver templates that support supplying an output projection. (or at least transforming them to the mapfiles output projection).... that reminds me I need to make a 
> ticket for one of those changes.
>>> http://trac.osgeo.org/mapserver/ticket/2961
>>>
>>> Anyway... I already did that.
>>> --- maptemplate.c	(revision 8844)
>>> +++ maptemplate.c	(working copy)
>>> @@ -3282,14 +3282,23 @@
>>>          }
>>>        }
>>>      }
>>> -    
>>> -    sprintf(repstr, "%f %f", (mapserv->resultshape.bounds.maxx + mapserv->resultshape.bounds.minx)/2, (mapserv->resultshape.bounds.maxy + mapserv->resultshape.bounds.miny)/2); 
>>> -    outstr = msReplaceSubstring(outstr, "[shpmid]", repstr);
>>> -    sprintf(repstr, "%f", (mapserv->resultshape.bounds.maxx + mapserv->resultshape.bounds.minx)/2);
>>> -    outstr = msReplaceSubstring(outstr, "[shpmidx]", repstr);
>>> -    sprintf(repstr, "%f", (mapserv->resultshape.bounds.maxy + mapserv->resultshape.bounds.miny)/2);
>>> -    outstr = msReplaceSubstring(outstr, "[shpmidy]", repstr);
>>> -    
>>> +   
>>> +    { 
>>> +	    rectObj tempExtent;
>>> +	    tempExtent.minx = mapserv->resultshape.bounds.minx;
>>> +	    tempExtent.maxx = mapserv->resultshape.bounds.maxx;
>>> +	    tempExtent.miny = mapserv->resultshape.bounds.miny;
>>> +	    tempExtent.maxy = mapserv->resultshape.bounds.maxy;
>>> +	    if(msProjectionsDiffer(&(mapserv->resultlayer->projection), &(mapserv->map->projection))) 
>>> + 	        msProjectRect(&(mapserv->resultlayer->projection), &mapserv->map->projection, &tempExtent);  
>>> +	    sprintf(repstr, "%f %f", (mapserv->resultshape.bounds.maxx + mapserv->resultshape.bounds.minx)/2, (mapserv->resultshape.bounds.maxy + mapserv->resultshape.bounds.miny)/2); 
>>> +	    outstr = msReplaceSubstring(outstr, "[shpmid]", repstr);
>>> +	    sprintf(repstr, "%f", (tempExtent.maxx + tempExtent.minx)/2);
>>> +	    outstr = msReplaceSubstring(outstr, "[shpmidx]", repstr);
>>> +	    sprintf(repstr, "%f", (tempExtent.maxy + tempExtent.miny)/2);
>>> +	    outstr = msReplaceSubstring(outstr, "[shpmidy]", repstr);
>>> +    }
>>> +
>>>      if(processExtentTag(mapserv, &outstr, "shpext", &(mapserv->resultshape.bounds), &(mapserv->resultlayer->projection)) != MS_SUCCESS)
>>>        return(NULL);
>>>      if(processExtentTag(mapserv, &outstr, "shpext_esc", &(mapserv->resultshape.bounds), &(mapserv->resultlayer->projection)) != MS_SUCCESS) /* depricated */
>>>
>>>
>>> 2) You can reproject using the OpenLayers code: Something along the lines of: coord = {'x': x_coord, 'y': y_coord}; OpenLayers.Projection.transform({'x': lon, 'y': lat}, <insert your projection here>, LatLongProjection); ll = {'lon': coord.x, 'lat': 
> coord.y} ; Map.panTo(ll);
>>> (From memory, check the projection call from geomoose/main.js)
>>>
>>>>>> Brent Fraser <bfraser at geoanalytic.com> 04/24/09 4:32 PM >>>
>>>   I've got a layer in geographic coordinates I'd like to do a GeoMoose Search on.  Unfortunately, Mapserver's shpminx/shpmaxx/shpminx/shpmaxx template values return the shape extents in the layer's coordinate system, not the map coordinate system, so
>  the GeoMoose Map.zoomToViewString call in the itemquery template does not work.
>>>   Has anyone got a Map.zoomToLatLonViewString function laying around?
>>>
>>> My other options are:
>>>   Convert the layer to the map projection (a maintenance nightmare)
>>>   Enhance Mapserver's [shpmin} handling to match it's [shpext proj=] abilities (too much work right now)
>>>
>>> Thanks!
>>> Brent Fraser
>>>
> 
> ------------------------------------------------------------------------------
> Crystal Reports &#45; New Free Runtime and 30 Day Trial
> Check out the new simplified licensign option that enables unlimited
> royalty&#45;free distribution of the report engine for externally facing 
> server and web deployment.
> http://p.sf.net/sfu/businessobjects
> _______________________________________________
> Geomoose-users mailing list
> Geomoose-users at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/geomoose-users
> 




More information about the Geomoose-users mailing list