| glennuser 03-18-2004, 09:51 AM I have seen posts discussing how to find pushpins in shapes. The solution suggested was to use the 'Dataset.QueryShape' method.
As a new MapPoint user, I can't figure out *how* to set things up (in code) in order to use this method.
Assuming I have a map with shapes, and each shape has a pushpin in (on?) it, what steps, in code, would I need to go through? I would like to generate a collection (dataset? resultset?) that holds all pushpins found in each shape. (My sense is that we're talking on the order of 10 lines of code.)
Thanks very much. John Meyer 03-18-2004, 01:32 PM Have you taken a look in mappoint.chm ? It should be loacated in your mappoint directory. (compiled help file)
Open it
click programming information (Last item in list)
click Microsoft MapPoint Visual Basic Reference
click Methods
click QueryShape method glennuser 03-18-2004, 01:40 PM Yes, I was there.
But this code segment (which is from that example):
'Let user create a data map
Set objDataSet = _
objApp.ActiveMap.DataSets.ShowImportWizard
opens up a dialog box, and prompts me to import a data file that I don't have.
Why must I import a data file in order to retrieve a Recordset of pushpins and shapes? John Meyer 03-18-2004, 01:48 PM Just comment that out and run it again. Thats there for example in case you do not have and data on the map (pushpins) glennuser 03-18-2004, 02:15 PM But doesn't that still leave me without a valid objDataSet?
This line will fail:
Set objRecords = objDataSet.QueryShape(objShape)
As you suggest, there should be a dataset available from my pushpins.
I found this in the help file:
" ... or when you create a Pushpin with the Create Pushpin drawing tool. The default name of this data set is My Pushpins. "
So, I tried this:
Set objDataSet = objmap.DataSets("My Pushpins")
But I get the following error:
"The requested member of the collection does not exist. Use a valid name or index number." John Meyer 03-18-2004, 02:38 PM Ok, Here is an example that will create a drivetimezone (a shape) and report how many pushpins are in it. (Put a pushpin in Tampa, FL) You should be able to adapt this to work with other shapes as needed.... My MapPoint Control is named MapPointCtl so you may need to edit the code or change the name of your control.... Let me know if you have success with this sample.
Dim objmap As MapPointCtl.Map
Dim objDataSet As MapPointCtl.DataSet
Dim objRecords As MapPointCtl.Recordset
Dim objshape As MapPointCtl.Shape
Dim lngCount As Long
Dim objloc1 As MapPointCtl.Location
Dim aDriveTimeZone As MapPointCtl.Shape
Set objmap = MappointControl1.ActiveMap
Set objloc1 = objmap.FindResults("Tampa, FL").Item(1)
Set objshape = objmap.Shapes.AddDrivetimeZone(objloc1, 20 * geoOneMinute)
objshape.Select
For Each objDataSet In objmap.DataSets
Set objRecords = objDataSet.QueryShape(objshape)
objRecords.MoveFirst
Do While Not objRecords.EOF
lngCount = lngCount + 1
objRecords.MoveNext
Loop
Next
MsgBox "Number of records in shape: " & lngCount glennuser 03-18-2004, 03:08 PM Fantastic.
Thanks very much for your continued assistance.
I think I'm on my way -- thanks to you.
Best wishes,
-- Glenn John Meyer 03-18-2004, 03:11 PM Thanks for the kind words,
Take care, Anonymous 03-28-2004, 04:50 PM Ok, Here is an example that will create a drivetimezone (a shape) and report how many pushpins are in it. (Put a pushpin in Tampa, FL) You should be able to adapt this to work with other shapes as needed.... My MapPoint Control is named MapPointCtl so you may need to edit the code or change the name of your control.... Let me know if you have success with this sample.
Dim objmap As MapPointCtl.Map
Dim objDataSet As MapPointCtl.DataSet
Dim objRecords As MapPointCtl.Recordset
Dim objshape As MapPointCtl.Shape
Dim lngCount As Long
Dim objloc1 As MapPointCtl.Location
Dim aDriveTimeZone As MapPointCtl.Shape
Set objmap = MappointControl1.ActiveMap
Set objloc1 = objmap.FindResults("Tampa, FL").Item(1)
Set objshape = objmap.Shapes.AddDrivetimeZone(objloc1, 20 * geoOneMinute)
objshape.Select
For Each objDataSet In objmap.DataSets
Set objRecords = objDataSet.QueryShape(objshape)
objRecords.MoveFirst
Do While Not objRecords.EOF
lngCount = lngCount + 1
objRecords.MoveNext
Loop
Next
MsgBox "Number of records in shape: " & lngCount
hi,
i tried the exact thing above and it doesnt return any records. i've been trying this for quite a while now, but numerous attempts have only led to frustration. it doesnt give an errormessage or something, but the above example doesnt create any datasets.
is a dataset supposed to be created automatically when a queryshape is executed? is there some setting for this?
would be thankfull for any replies.. John Meyer 03-28-2004, 05:26 PM Did you add some pushpins to the tampa area? Anonymous 03-28-2004, 06:02 PM eehm.. no.. first i use some area around my home, which is in the UK.. but i presume there is no functional difference between european and usa version of mappoint in this aspect?
the drivetimezone i made has plenty of locations in it, the ones that come with mappoint, eg. banks, petrol stations etc.
it was my idea to get these "pushpins" in the recordset, not some pushpins i added myself beforehand.
I tried to zoom in, but it didnt make any difference which zoom level i used, neither did the type of map: i usually have terain map but datamap didnt show any records either *sigh*
i can find location objects with the findnearby method, but that gives such an ugly grid on my map.. so i try it with shapes as a last resort!
so if the queryshape method works only with my own pushpins, can you let me know?
thanks,
mischka John Meyer 03-28-2004, 06:08 PM Yes this was only for pushpins you added yourself, Sorry... Anonymous 03-29-2004, 08:36 AM Yes this was only for pushpins you added yourself, Sorry...
hmmm... bugger :( but thanks for the answer,at least i know now the problem is not in my programming-abilities...
so, is there any other way to get all the "points of interest" within X geo-units around location Y? this excludes the findnearby, which makes the ugly grid on the map....
thx
mischka | |