PHP/Mapscript, Find what Shape of layer one is each point of layer 2 in

Ed Martin edman007x at MAC.COM
Fri Dec 24 19:34:18 EST 2004


i have a layer of cities and a layer of counties, and right now i'm
trying to make a table in mysql of that county each city is in, the
problem is i can't figure out how should go about doing this, what i
have done so far is make an array of all the points in the cities
layer, but then after that i'm stuck as to how to determine what county
that point it is in, this is the code i have so far, and i just get
thousands of errors saying nothing found

-----code-----
$map = ms_newMapObj("map/map.map");
$cities = $map->getlayerbyname('Cities');
$counties = $map->getlayerbyname('County');
$cities->open();
$id = 0;
$query = 'SELECT id FROM cities ORDER BY id DESC';
$result= mysql_query($query);
$id_max = mysql_fetch_array($result, MYSQL_NUM);
$id_max[0]--;
//get the shape, then line, then point for each city
while ($city_shape[$id] = $cities->getshape(-1, $id)){
     if ($id >= $id_max[0]){
         break;
     }
     $id++;
}
$cities->close();
$size = sizeof($city_shape);
$dont_touch = array();
for ($i = 0; $i<$size; $i++){
     $city_line[$i] = $city_shape[$i]->line(0);
     if (!is_object($city_line[$i])){
         $dont_touch[] = $i;//for some reason 3 lines return false
instead of a point
         //so this makes an array of those so they can be skipped
     }
}
for ($i = 0; $i<$size; $i++){
     if (in_array($i, $dont_touch)){
         continue;//skip the non-objects
     }
     $city_point[$i] = $city_line[$i]->point(0);
}
for ($i = 0; $i<$size; $i++){
     if (in_array($i, $dont_touch)){
         continue;//skip the non-objects
     }
     $counties->querybypoint($city_point[$i], MS_SINGLE, 1);//this justs
gives errors
     //once i can get the id of the county i feel i will be able to dump
it to mysql
}


---relevant parts of mapfile---

MAP
        #The First layer is drawn first so it will be under everything else
        NAME "Ads By Town"
        EXTENT -126.30536309017 6.3903743998824 -63.798263662392
68.919064491698
#       EXTENT -179.133 17.675 179.788 71.398
        IMAGETYPE jpeg
        IMAGECOLOR -1 -1 -1
        STATUS ON
        SIZE 600 600
        UNITS dd
        SYMBOLSET "symbols.txt"
        OUTPUTFORMAT
                NAME jpeg
                DRIVER "GD/JPEG"
                MIMETYPE "image/jpeg"
                IMAGEMODE RGB
                EXTENSION "jpg"
                FORMATOPTION "QUALITY=65"
        END
        #layer for the counties
        LAYER
                NAME "County"
                TYPE POLYGON
                STATUS DEFAULT
                DATA
"/usr/local/apache/htdocs/adsbytown/mapserver/map/data/countyp020"
                MAXSCALE 8203600
                CLASS
                        NAME "County Boarder"
                        STYLE
                                OUTLINECOLOR 0 200 200
                                SYMBOL "dashed_line"
                                SIZE 1
                        END
                END
        END
        #layer for the cities
        LAYER
                NAME "Cities"
                TYPE POINT
                STATUS default
                DATA "/usr/local/apache/htdocs/adsbytown/mapserver/map/data/ci10de03"
                LABELMAXSCALE 1025400
                LABELITEM "NAME"
                MAXSCALE 4101800
                LABELCACHE on
                TOLERANCE 25
                TOLERANCEUNITS miles
                METADATA
                        "title" "Ads By Town Cities"
                        "author" "Me!"
                END
                #this is for cities default
                CLASS
                        TEMPLATE void
                        NAME "City"
                        LABEL
                                ANGLE 0
                                ANTIALIAS FALSE
                                COLOR 0 0 0
                                SIZE small
                                TYPE bitmap
                                BUFFER 2
                                OFFSET 0 5
                                POSITION lc
                                #FORCE TRUE#force everything to be labeled (text overlaps)

                        END
                        STYLE
                                OUTLINECOLOR 255 0 0
                                COLOR 255 0 0
                                SYMBOL 1
                                SIZE 2
                        END
                END




More information about the mapserver-users mailing list