Re: [mapserver-users] converting line object to series of points

2010-04-15 Thread Mark Brooks

Thanks for your insights and help.

The lines I'm working with will have multiple points.  They are 
hurricane tracks.  The tracks are made of points, about 3-12 hours 
apart.  Therefore, sometimes the points are close and other times very 
far away from each other.  I can easily connect the track points to 
create a line.  But I need the points in between each observation so 
that I can determine what county landfall occurs.  The y=mx+b method 
will work, but I was hoping there may be an easier to do it.  Or perhaps 
I'm making the problem too complicated to begin with??


Mark


Bob Basques wrote:

All,


If you don't care about the actual coordinates of the points along the 
line (just trying to display things) I wonder if a linetype/combined 
with a scaling option would get you what you are looking for.



bobb


 >>> Andy Colson  wrote:

On 4/15/2010 10:51 AM, Mark Brooks wrote:
 > I'm using PHP Mapscript.  I need a point every X meters along the line.
 >
 > Mark
 >
 >
 > Andy Colson wrote:
 >> On 4/15/2010 10:24 AM, Mark Brooks wrote:
 >>> I have a line object that I need to to turn into points. How can I
 >>> create a series of points from the line object?
 >>>
 >>> Mark
 >>> NC State University
 >>
 >> A line has many many points. Which are you interested in? Just the
 >> first and last? Any one point on the line? The mid-point? A point
 >> every meter along the line? The closes point on the line to some other
 >> object?
 >>
 >> I know of two options:
 >> 1) use PostGIS:
 >> select st_centroid(the_geom) from layer
 >>
 >> 2) use mapscript
 >>
 >>
 >> -Andy
 >

Does the line have a single start and end point?  (a MULTILINE record
can have multiple lines (so multiple start and end points, all stuck
togethor).

In general, find the start and end points, use them to find the equation
of the line (y=mx+b if I recall correctly), then use that equation to
find one corrd based on another.  (so, plug in a buch of x's to find
their y's).

-Andy


___
mapserver-users mailing list
mapserver-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-users


Re: [mapserver-users] converting line object to series of points

2010-04-15 Thread Mark Brooks

I'm using PHP Mapscript.  I need a point every X meters along the line.

Mark


Andy Colson wrote:

On 4/15/2010 10:24 AM, Mark Brooks wrote:

I have a line object that I need to to turn into points.  How can I
create a series of points from the line object?

Mark
NC State University


A line has many many points.  Which are you interested in?  Just the 
first and last?  Any one point on the line?  The mid-point?  A point 
every meter along the line?  The closes point on the line to some other 
object?


I know of two options:
1) use PostGIS:
select st_centroid(the_geom) from layer

2) use mapscript


-Andy


___
mapserver-users mailing list
mapserver-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-users


[mapserver-users] converting line object to series of points

2010-04-15 Thread Mark Brooks
I have a line object that I need to to turn into points.  How can I 
create a series of points from the line object?


Mark
NC State University
___
mapserver-users mailing list
mapserver-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-users


Re: [mapserver-users] distance between line and a given point usingmapscript

2009-07-28 Thread Mark Brooks
I got the looping through each result.  However, all distances are
calculated to -1, which I know can't be right.  In debugging, I'm also
echo'ing the shape index for each result, but it's always the same.  Am I
constructing the layer correctly?


// create array of points from database query results.
for ($i=0; $row=mysql_fetch_assoc($result); $i++){

$points[$row['snum']][$i]['lat'] = $row['lat'];
$points[$row['snum']][$i]['lon'] = $row['lon'];

} // End loop through points

// create map object
$map = ms_newMapObj('wms.map');

// create new layer for hurricane tracks.
$my_layer = ms_newLayerObj($map);

// set some fields for this new layer
$my_layer->set("toleranceunits","miles");
$my_layer->set("tolerance","20");

// Create new class and add TEMPLATE.
$my_class = ms_newClassObj($my_layer);
$my_class->set("template",'query_template.html');

// Loop through points, create line for each storm, and add track points
to new line object.
while (list($snum,$coordinates)=each($points)){

// Create new line object
$my_line = ms_newLineObj();

// Loop through each point coordinate for this snum
while (list($num,$coordinate)=each($coordinates)){

// Create new point object
$my_point = ms_newpointObj();
$my_point->setXY($coordinate['lon'],$coordinate['lat']);

// Add point to line object
$my_line->add($my_point);

} // done adding this storm's points to the line object

// Now create a new shape object
$my_shape = ms_newShapeObj(MS_SHAPE_LINE);
$my_shape->add($my_line);

// Add feature to the layer
$my_layer->addFeature($my_shape);

} // end creating and adding points to line objects and line objects to
the layer.

// Draw map.
$map->draw();

// Make a new point object that will be our reference point.
$my_ref_point = ms_newpointObj();
$my_ref_point->setXY(-78.7,35.4);  // user-entered coordinates of where we
are querying from.

// Run a point query on the line object layer.
if (@$my_layer->queryByPoint($my_point,MS_MULTIPLE,-1)==MS_SUCCESS){

// Loop through results.
$num_results = $my_layer->getNumResults();
echo "# results = $num_results\n\n";

// Loop through each result
for ($num=0; $num<$num_results; $num++){
echo "result # $num:\n";

// Get this result
$my_result = $my_layer->getResult($num);

//$my_shape =
$my_layer->getShape($my_result->tileindex,$my_result->shapeindex);
 // Get the shape
echo "shapeindex = ".$my_result->shapeindex."\n";
$my_shape = $my_layer->getFeature($my_result->shapeindex);
 // Get the feature
echo "distanceToShape =
".$my_ref_point->distanceToShape($my_shape)."\n\n"; //
calculate distance from ref point to feature

    }
}



On Mon, July 27, 2009 11:54 pm, Steve Lime wrote:
> There are lots of samples that show you how to loop through a set of
> search
> results. There's a getNumResults() method for layer objects and then a
> getResult()
> method to retrieve each one individually.
>
> Steve
>
>>>> Mark Brooks  07/27/09 9:50 AM >>>
> Steve,
>
> This is a huge help.  The only thing I had not figured out was the
> 'toleranceunits' and 'tolerance' fields.  I appreciate your help!
>
> I intend to add many, possible hundreds, lines to a layer.  Then query
> it with a given reference point.  How do I get the number of results and
> then loop through each one?
>
> Best Regards,
> Mark
>
>
> Steve Lime wrote:
>>> How do I query a layer with one or more line features to find all
>>> features with X miles of a given point?
>>
>> Your line layer should like so:
>>
>>   LAYER
>> NAME 'lines'
>> TYPE LINE
>> ...other junk...
>> TEMPLATE 'dummy' # to be queryable
>> TOLERANCEUNITS MILES
>> TOLERANCE X
>>   END
>>
>> Then in mapscript you'd do a
>>
>>   $my_layer->queryByPoint($my_point, MS_MULTIPLE, -1);
>>
>> The buffer parameter is used to override a layer tolerance so setting to
>> -1 tells
>> the method to ignore it.  If you do use it then it's given in the units
>> of the layer
>> being searched (before any projection).
>>
>> Does that help?
>>
>> Steve
>>
>>>>> Mark Brooks  07/24/09 3:26 PM >>>
>> I&#

Re: [mapserver-users] distance between line and a given point usingmapscript

2009-07-27 Thread Mark Brooks

Steve,

This is a huge help.  The only thing I had not figured out was the 
'toleranceunits' and 'tolerance' fields.  I appreciate your help!


I intend to add many, possible hundreds, lines to a layer.  Then query 
it with a given reference point.  How do I get the number of results and 
then loop through each one?


Best Regards,
Mark


Steve Lime wrote:

How do I query a layer with one or more line features to find all
features with X miles of a given point?


Your line layer should like so:

  LAYER
NAME 'lines'
TYPE LINE
...other junk...
TEMPLATE 'dummy' # to be queryable
TOLERANCEUNITS MILES
TOLERANCE X
  END

Then in mapscript you'd do a 


  $my_layer->queryByPoint($my_point, MS_MULTIPLE, -1);

The buffer parameter is used to override a layer tolerance so setting to -1 
tells
the method to ignore it.  If you do use it then it's given in the units of the 
layer
being searched (before any projection).

Does that help?

Steve


Mark Brooks  07/24/09 3:26 PM >>>

I'm trying to create several new line objects and then find the lines
that are within x miles of a given point.  (i.e., how far away a given
point is from the track of a hurricane or the path of a ship).  I'm
having some difficulties and I hope someone can help.

How do I query a layer with one or more line features to find all 
features with X miles of a given point?


Here is how I'm approaching the problem in PHP:

// Test array of points.  This is used to make a line.
$points[0]['lat'] = 35.5;
$points[0]['lon'] = -78.8;
$points[1]['lat'] = 36.5;
$points[1]['lon'] = -79.8;
$points[2]['lat'] = 37.5;
$points[2]['lon'] = -80.1;

// make new map object.
$map = ms_newMapObj('mapdata/mymap.map');

// Create new line
$my_line = ms_newLineObj();

// Loop through points, and add to the line
while (list(,$coordinate)=each($points)){

 // Create new point object
 $my_point = ms_newpointObj();
 $my_point->setXY($coordinate['lon'],$coordinate['lat']);

 // Add point to line object
 $my_line->add($my_point);
}

// Now create a new shape
$my_shape = ms_newShapeObj(MS_SHAPE_LINE);
$my_shape->add($my_line);

// create new layer
$my_layer = ms_newLayerObj($map);

// set some fields for this new layer
//$my_layer->set("units","miles");  // does not seem to work as expected

// Create new class and add TEMPLATE.  This is required for queries on 
the layer to work?

$my_class = ms_newClassObj($my_layer);
$my_class->set("template",'/home/www/html/query_template.html');

// Add feature to the layer
$my_layer->addFeature($my_shape);

// Draw map. Query doesn't work if I don't do this now.
$map->draw();

// Make a new point object that will be our ref point
// to check how far away the line is from this point.
$my_point = ms_newpointObj();
$my_point->setXY(-82,36); // lon, lat

// Run a point query on the line object layer; layer must have a class 
with a LAYER TEMPLATE value
// The third argument is the buffer tolerance.  Default unit is pixels? 
  Must figure out how to make miles or km.

if ($my_layer->queryByPoint($my_point,MS_SINGLE,1)==MS_SUCCESS){

 $my_result = $my_layer->getResult(0);  // Get the result
 $my_layer = 
$my_layer->getShape($my_result->tileindex,$my_result->shapeindex);  // 
Get the shape


}
___
mapserver-users mailing list
mapserver-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-users




--

   Mark Brooks
   State Climate Office of North Carolina
   Box 7236, NC State University
   Raleigh, NC 27695-7236

   Phone:  919.515.1446
   Fax:  919.515.1441
___
mapserver-users mailing list
mapserver-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-users


[mapserver-users] distance between line and a given point using mapscript

2009-07-24 Thread Mark Brooks

I'm trying to create several new line objects and then find the lines
that are within x miles of a given point.  (i.e., how far away a given
point is from the track of a hurricane or the path of a ship).  I'm
having some difficulties and I hope someone can help.

How do I query a layer with one or more line features to find all 
features with X miles of a given point?


Here is how I'm approaching the problem in PHP:

// Test array of points.  This is used to make a line.
$points[0]['lat'] = 35.5;
$points[0]['lon'] = -78.8;
$points[1]['lat'] = 36.5;
$points[1]['lon'] = -79.8;
$points[2]['lat'] = 37.5;
$points[2]['lon'] = -80.1;

// make new map object.
$map = ms_newMapObj('mapdata/mymap.map');

// Create new line
$my_line = ms_newLineObj();

// Loop through points, and add to the line
while (list(,$coordinate)=each($points)){

// Create new point object
$my_point = ms_newpointObj();
$my_point->setXY($coordinate['lon'],$coordinate['lat']);

// Add point to line object
$my_line->add($my_point);
}

// Now create a new shape
$my_shape = ms_newShapeObj(MS_SHAPE_LINE);
$my_shape->add($my_line);

// create new layer
$my_layer = ms_newLayerObj($map);

// set some fields for this new layer
//$my_layer->set("units","miles");  // does not seem to work as expected

// Create new class and add TEMPLATE.  This is required for queries on 
the layer to work?

$my_class = ms_newClassObj($my_layer);
$my_class->set("template",'/home/www/html/query_template.html');

// Add feature to the layer
$my_layer->addFeature($my_shape);

// Draw map. Query doesn't work if I don't do this now.
$map->draw();

// Make a new point object that will be our ref point
// to check how far away the line is from this point.
$my_point = ms_newpointObj();
$my_point->setXY(-82,36); // lon, lat

// Run a point query on the line object layer; layer must have a class 
with a LAYER TEMPLATE value
// The third argument is the buffer tolerance.  Default unit is pixels? 
 Must figure out how to make miles or km.

if ($my_layer->queryByPoint($my_point,MS_SINGLE,1)==MS_SUCCESS){

$my_result = $my_layer->getResult(0);  // Get the result
$my_layer = 
$my_layer->getShape($my_result->tileindex,$my_result->shapeindex);  // 
Get the shape


}
___
mapserver-users mailing list
mapserver-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-users


[mapserver-users] Re: shade a county

2008-09-23 Thread Mark Brooks
I figured it out.  It was actually pretty easy.  For reference to others 
who might need to do this also, I'll post my methodology.  I also have 
one outstanding question at the end...


Mapscript snippet looks like this:

// Make a new point object
$cnty_layer = $map->getLayerByName('cnty');
$my_point = ms_newpointObj();
$my_point->setXY($lon,$lat);

// Run a point query on the county layer.
// layer must have a class with a LAYER TEMPLATE value
if ($cnty_layer->queryByPoint($my_point,MS_SINGLE,1)==MS_SUCCESS){
   $cnty_result = $cnty_layer->getResult(0);  // Get the result
   $cnty_layer->open();// Open layer for use with getShape()

$cnty_shape=$cnty_layer->getShape($cnty_result->tileindex,$cnty_result->shapeindex); 



   // Draw the shape onto the shaded county layer
   $cnty_shade = $map->getLayerByName('shade_red');
   $cnty_shape->draw($map, $cnty_shade, $image);
}


Mapfile snippet that goes along with the above looks like this:

LAYER
   NAME shade_red
   TYPE POLYGON
   STATUS ON
   TRANSPARENCY 50   # use OPACITY in mapserver v5
   CLASS
NAME "Red County"
COLOR 187 0 0
   END
END


Notice the transparency in the layer above.  I'm still on mapserver 4.x. 
 The problem is that the layer doesn't draw with any transparency, no 
matter what I put as the value.  Any ideas?


Mark


Mark Brooks wrote:
I have a shapefile of type polygon of all counties in the United States. 
 Given a latitude/longitude point, I want to shade/hatch the county that 
it's in.  I'm not sure of the best way to do this.  Any suggestions?  
I'm working with PHP Mapscript by the way.


Mark

___
mapserver-users mailing list
mapserver-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-users


[mapserver-users] shade a county

2008-09-23 Thread Mark Brooks
I have a shapefile of type polygon of all counties in the United States. 
 Given a latitude/longitude point, I want to shade/hatch the county 
that it's in.  I'm not sure of the best way to do this.  Any 
suggestions?  I'm working with PHP Mapscript by the way.


Mark
___
mapserver-users mailing list
mapserver-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-users


[mapserver-users] satellite / aerial imagery

2008-06-28 Thread Mark Brooks
I am working on a mapserver project and need satellite or aerial imagery,
preferably at a very high resolution.  Kind of like google maps satellite
view.  I assume raster or geotif would be the ideal file type.  I only
need imagery for North America.  Can anyone suggest a good, hopefully
free, resource for this?

Much thanks,
Mark
NC State University
___
mapserver-users mailing list
mapserver-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-users


[mapserver-users] find max value in mapfile?

2008-06-17 Thread Mark Brooks

We have a shapefile of type 'point'.  Is there a way to find the maximum
value of all points in this shapefile?  It would be cool to be able to
do this in the mapfile.  We're using PHP mapscript and want to create a
dynamic color ramp based on the max/min values of the shapefile.

Mark

___
mapserver-users mailing list
mapserver-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-users