MapTools.org

AW: AW: [maplab-users] maplab/mapserver/PHP-mapscript function to search a object

Andreas Berweger andreas.berweger@bluewin.ch
Tue, 8 Oct 2002 19:10:32 +0200
Done!! Thanks Paul!! With one limitation at the moment ... you could only
zoom to objects they are in your actually picture ...

Here some comments for the list ...
$oMapSession->oMap->shapepath works fine when you use relative paths to your
data directory. the relativ path starts in your Application directory (for
example: ../../Daten/data_ww/)

ok and here is our ( Paul's :) Code:

/*
============================================================================
 * Parzellennummer suchen
 * =========================================================================
*/
if ( $http_form_vars["parcel-number"])
{
	// the parcel number to query for
	$szParcelNumber = $http_form_vars["parcel-number"];

	// the current extents will be the default if we fail.
	$oExtents = $oMapSession->oMap->extent;
	$oldExtents=$oExtents;

	//first we need a handle on the layer, let's assume that we have
	//it's name
	$oParcelLayer = $oMapSession->oMap->getLayerByName( "Parzellen" );

	// set up the layer for a query in ms 3.6 - in 3.7 we don't need
	// to do this, we can just use querybyattribute. Here we assume
	// that the data file associated with the layer has an attribute
	// called parcel_number that we are querying.
	$oParcelLayer->set( "filteritem", "Nummer" );
	$oParcelLayer->setFilter("\"$szParcelNumber\"");

	// use querybyattribute to generate the result, assume a single
	// one for simplicity but this can be extended to multiple
	// results easily
	$oParcelLayer->queryByAttributes( MS_SINGLE );

	//now check to see if there are any results?
	if ($oParcelLayer->getNumResults() > 0 )
	{
		//at least one result, assume only one for this example
		$oResult = $oParcelLayer->getResult( 0 );

		//oResult is a resultCacheMemberObj
		$oParcelLayer->open($oMapSession->oMap->shapepath);
		$oShape = $oParcelLayer->getShape(
$oResult->tileindex,$oResult->shapeindex );
		$oExtents = $oShape->bounds;
		$oShape->free();

		//at this point we might add a buffer to the extents
		$nXBuffer = ( $oExtents->maxx - $oExtents->minx )*0.05;
		$nYBuffer = ( $oExtents->maxy - $oExtents->miny )*0.05;
		$nMinX = $oExtents->minx - $nXBuffer;
		$nMaxX = $oExtents->maxx + $nXBuffer;
		$nMinY = $oExtents->miny - $nYBuffer;
		$nMaxY = $oExtents->maxy + $nYBuffer;
		$oExtents->setextent( $nMinX, $nMinY, $nMaxX, $nMaxY );
	}

	// now use $oMapNavigator to navigate to the parcel
	// location. There are two useful options now. We
	// can zoom to a rectangle which we have calculated or
	// to a point and scale. Let's assume we have calculated
	// a rectangle and put a buffer around it if necessary.
	$breite=$oMapSession->oMap->width;
	$hoehe=$oMapSession->oMap->height;

$px1=$breite/($oldExtents->maxx-$oldExtents->minx)*($oExtents->minx-$oldExte
nts->minx);

$px2=$breite/($oldExtents->maxx-$oldExtents->minx)*($oExtents->maxx-$oldExte
nts->minx);

$py1=$hoehe/($oldExtents->maxy-$oldExtents->miny)*($oldExtents->maxy-$oExten
ts->maxy);

$py2=$hoehe/($oldExtents->maxy-$oldExtents->miny)*($oldExtents->maxy-$oExten
ts->miny);

	$oMapNavigator->zoomRectangle($px1, $py2, $px2, $py1);

	// alternately if it's a point and a scale ...
	//$oMapNavigator->zoomScale( 1000, 100, 100 );
}

Thanks again Andreas Berweger BHA AG




> -----Ursprungliche Nachricht-----
> Von: Paul Spencer [mailto:pgs@magma.ca]
> Gesendet: Dienstag, 8. Oktober 2002 16:06
> An: Andreas Berweger
> Betreff: Re: AW: [maplab-users] maplab/mapserver/PHP-mapscript function
> to search a object
>
>
> Andreas, glad I could help.  Sorry, I didn't check the code, it was just
> a rough example I threw together.  I would have been very suprised if it
> was right the first time :)  If your layer is correctly configured, you
> should have been able to access a shape in the layer using
> $oLayer->getShape().  You can calculate the path to your layer's data by
> getting the shapepath from the map object
> ($oMapSession->oMap->shapepath) unless you use absolute paths in the
> layer's data attribute.  If this doesn't work, try a post on
> mapserver-users, I'm sure you'll get lots of help :)
>
> Cheers,
>
> Paul
>
> Andreas Berweger wrote:
> > Thanks for your help Paul!!
> > It helps a lot and looks very easy/logical. But i have some
> Problems with
> > accessing Mapinfo/OGR files through the "getshape()" command. I
> have used
> > your syntax as you described in your mail. it works great. but
> when i call
> > the "getshape()" command the following php error occurs
> >
> >
> > $oShape =
> > $oParcelLayer->getShape($oResult->tileindex,$oResult->shapeindex );
> >
> > -> MapServer Error in msOGRLayerNextShape(): Assertion failed:
> OGR layer not
> > opened!!!
> >
> > i have read in some posts that i have to open the layer
> explicitly before
> > using get shape() and close it after. Command: int open(string
> shapepath)
> >
> > http://mapserver.gis.umn.edu/wilma/mapserver-users/0207/msg00542.html
> >
> > But how to open a OGR layer through php/mapscript? Whats the
> shapepath for
> > OGR layers ... with $map->shapepath it doesn't work ...
> >
> >
> > Thanks a lot for you help and time paul
> >
> >
> > P.S.  i have also changed the foolowing lines because we use mapserver
> > version 3.6.2 (3.7.0)
> >
> >       $oParcelLayer->queryByAttribute( MS_SINGLE ); //
> > $oParcelLayer->queryByAttributes( MS_SINGLE )
> >
> >       $oParcelLayer->set( "filteritem", "Nummer" ); //
> "filteritem" in small
> > cases
> > 	$oParcelLayer->setFilter("\"$szParcelNumber\""); // replaces (
> > $szParcelNumber )
> >
> > 	$oShape =
> > $oParcelLayer->getShape($oResult->tileindex,$oResult->shapeindex );
> > //shapeid to shapeindex
> >
> >
> >
> >>-----Ursprungliche Nachricht-----
> >>Von: maplab-users-admin@dmsolutions.ca
> >>[mailto:maplab-users-admin@dmsolutions.ca]Im Auftrag von Paul Spencer
> >>Gesendet: Dienstag, 8. Oktober 2002 03:59
> >>An: Andreas Berweger BHA AG; maplab-users; mapserver-users
> >>Betreff: Re: [maplab-users] maplab/mapserver/PHP-mapscript function to
> >>search a object
> >>
> >>
> >>Andreas,
> >>
> >>cool app :)  I think I can help point you in the right direction.  My
> >>appologies if there is too much detail here and you have already figured
> >>some/all of this out.  I am hoping to also help others who may not have
> >>tried to customize their gmapfactory application.
> >>
> >>Let's assume that your application is called MyApp and is in a directory
> >>called MyApp under maplab-2.0rc3/projects/gmf_apps/MyApp/.
> >>
> >>The main user interface file is called MyApp_contents.php.  You will add
> >>your new input box to this file in the appropriate location.  It should
> >>be easy to determine where to put it, there are comments ;)
> >>
> >>The next file of interest is called MyApp.php.  This is the main file
> >>that does all the work for navigation among other things.  In here are a
> >>series of if() statements that check for various modes of navigation
> >>that the user could have performed.  You will add an if() here something
> >>like:
> >>
> >>if ( $http_form_vars["parcel-number"] )
> >>{
> >>	// the parcel number to query for
> >>	$szParcelNumber = $http_form_vars["parcel-number"];
> >>
> >>	// the current extents will be the default if we fail.
> >>	$oExtents = $oMapSession->oMap->extents;
> >>
> >>	//first we need a handle on the layer, let's assume that we have
> >>	//it's name
> >>	$oParcelLayer = $oMapSession->oMap->getLayerByName( "Parcels" );
> >>
> >>	// set up the layer for a query in ms 3.6 - in 3.7 we don't need
> >>	// to do this, we can just use querybyattribute.  Here we assume
> >>	// that the data file associated with the layer has an attribute
> >>	// called parcel_number that we are querying.
> >>	$oParcelLayer->set( "FILTERITEM", "parcel_number" );
> >>	$oParcelLayer->setFilter( $szParcelNumber );
> >>
> >>	// use querybyattribute to generate the result, assume a single
> >>	// one for simplicity but this can be extended to multiple
> >>	// results easily
> >>	$oParcelLayer->queryByAttribute( MS_SINGLE );
> >>
> >>	//now check to see if there are any results?
> >>	if ($oParcelLayer->getNumResults() > 0 )
> >>	{
> >>		//at least one result, assume only one for this example
> >>		$oResult = $oParcelLayer->getResult( 0 );
> >>		//oResult is a resultCacheMemberObj
> >>		$oShape = $oParcelLayer->getShape( $oResult->tileindex,
> >>						   $oResult->shapeid );
> >>		$oExtents = $oShape->bounds;
> >>		$oShape->free();
> >>
> >>		//at this point we might add a buffer to the extents
> >>		$nXBuffer = ( $oExtents->maxx - $oExtents->minx )*0.05;
> >>		$nYBuffer = ( $oExtents->maxy - $oExtents->miny )*0.05;
> >>		$nMinX = $oExtents->minx - $nXBuffer;
> >>		$nMaxX = $oExtents->maxx + $nXBuffer;
> >>		$nMinY = $oExtents->miny - $nYBuffer;
> >>		$nMaxY = $oExtents->maxy + $nYBuffer;
> >>		$oExtents->setExtents( $nMinX, $nMinY, $nMaxX, $nMaxY );
> >>	}
> >>
> >>	// now use $oMapNavigator to navigate to the parcel
> >>	// location.  There are two useful options now.  We
> >>	// can zoom to a rectangle which we have calculated or
> >>	// to a point and scale.  Let's assume we have calculated
> >>	// a rectangle and put a buffer around it if necessary.
> >>	$oMapNavigator->zoomRectangle($oExtents->minx, $oExtents->miny,
> >>				      $oExtents->maxx, $oExtents->maxy);
> >>
> >>	// alternately if it's a point and a scale ...
> >>	// $oMapNavigator->zoomScale( $nScale, $nX, $nY );
> >>}
> >>
> >>The $oMapSession and $oMapNavigator are MapScript wrapper objects that
> >>we created to make working with a map object simpler for us, they can be
> >>found in the wrapper directory of your app.  The documentation for
> >>MapScript itself can be found at:
> >>
> >>http://www2.dmsolutions.ca/mapserver/php_mapscript/php_mapscript_d
> >>ocs36.html.
> >>
> >>Daniel has also mentioned that you should get the old GMap demo and look
> >>for GMapDumpQueryResults() for some related ideas to working with
> >>queries.  You should find it at
> >>http://www2.dmsolutions.ca/mapserver/dl/gmap-ms36.zip
> >>
> >>For questions like this, you may get faster response by posting to the
> >>mapserver-users mailing list, its very active and responsive ;)
> >>
> >>Cheers,
> >>
> >>Paul
> >>
> >>
> >>Andreas Berweger BHA AG wrote:
> >>
> >>>Hello together
> >>>
> >>>For first excuse my english. i'm from switzerland and im speaking a bad
> >>>english but well german.
> >>>im working on a project for little communes and there internet-maping.
> >>>
> >>>- i'm using maplab v2.0-rc3, mapserver 3.6.2 with OGR support
> >>
> >>and PHP 4.2.2
> >>
> >>>on windows
> >>>- my data commes from mapinfo Ver 6.0 and im using the tab
> >>
> >>files with OGR
> >>
> >>>first i have to say that maplab and mapserver are working very
> >>
> >>fine on my
> >>
> >>>system. maplab is easy to use and understand. The application
> >>
> >>i've made is
> >>
> >>>temporaly browsable at
> >>>
> >>>
> >>
> >>http://193.246.110.38/mappub/GIS/BHA_apps/GIS_warth-weiningen/GIS_
> >
> > warth-wein
> >
> >>ingen.phtml
> >>
> >>now my question:
> >>
> >>I have to made a textbox at the bottom of the legend. The user
> could input
> >
> > a
> >
> >>parcell-number and klick on search. now (i hope it would be possible)
> >>mapserver/maplab had to search for this parcell in the Layer
> >>"Liegenschaften"(=parcells in german) and zoom on it. Thats all :)
> >>"liegenschaften" is a polygon layer with the attributes
> parcell-number and
> >>area from mapinfo/OGR. You see im not so familar with PHP and mapscript.
> >>
> >>I hope you could help me an give me some hints. when i have forgotten
> >>something or you need data to help me i could give you ...
> >>
> >>Thanks a lot and good night
> >>
> >>
> >>
> >>
> >>_______________________________________________
> >>Maplab-users mailing list
> >>Maplab-users@dmsolutions.ca
> >>http://lists.dmsolutions.ca/mailman/listinfo/maplab-users
> >>
> >
> >
> >
> > --
> > Paul Spencer
> > Applications and Software Development
> > DM Solutions Group
> >
> >
> > _______________________________________________
> > Maplab-users mailing list
> > Maplab-users@dmsolutions.ca
> > http://lists.dmsolutions.ca/mailman/listinfo/maplab-users
> >
> >
>
>
> --
> Paul Spencer
> Applications and Software Development
> DM Solutions Group
>
>



This archive was generated by Pipermail.