Community of MapPoint and Bing Maps Users and Developers
This is a discussion on Calculate area of territory within the MapPoint Desktop Discussion forums, part of the Map Forums category; Hi all, I have create some territories on a map, i would like to now how many square kilometers that ...
| |||||||
| Today's Posts | Twitter Feed | Register | Blogs | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| Calculate area of territory I have create some territories on a map, i would like to now how many square kilometers that territory is. is this possible in Mappoint 2006 (territory is a collection of postalcodes). kind regards Ludo |
| |||
|
You can iterate through the territory dataset and get each postal code contained within a particular territory. Then you can use ActiveMap.Datasets.GetDemographics() to query for the area (sqkm) of each postal code. Add them up to get the total sqkm for each territory. HTH -Paul |
| |||
| Re: Calculate area of territory
Hi, Thanks for your reply Paul, I am not that experienced with MapPoint, I have tried to retrieve the data, but no succes... here is the code: Imports MapPoint Imports MapPoint.GeoMapRegion PublicClass Form1 Dim objapp As MapPoint.Application Dim objDataSet As MapPoint.DataSet Dim objDataMap As MapPoint.DataMap Dim objField As MapPoint.Field Dim objMap As MapPoint.Map Dim objLocation As MapPoint.Location Dim objShape As MapPoint.Shape PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load Dim km AsString 'Create Mappoint as Object and allow control objapp = CreateObject("Mappoint.application") objapp.Visible = True objapp.UserControl = True km = Getkm("77600") EndSub Function Getkm(ByVal Postcode AsString) 'Add data to current map objDataSet = objapp.ActiveMap.DataSets.GetDemographics(GeoCount ry.geoCountryFrance) objField = objDataSet.Fields(1) objDataMap = objDataSet.DisplayDataMap(GeoDataMapType.geoDataMa pTypeShadedArea, objField, GeoShowDataBy.geoShowByPostal1, , , , 15) 'Find and set location objMap = objapp.ActiveMap objLocation = objMap.FindResults(Postcode).Item(1) 'get data ??? Getkm = EndFunction I don't now what i do wrong to get the specific data.. kind regards Ludo |
| |||
| Re: Calculate area of territory
It may not be what you’re looking for but you can do this fairly easily in excel vba (or Access) by handling the data-bases independent of MP. I worked through an example in which I set up an excel workbook with sheet “Territories Definition” containing the ‘export to excel’ data from the MP territories map, sheet “Territory Names” containing a column with the territory names and sheet “Demographics” containing the area information. To get this area information use Data Mapping Wizard to plot a shaded map for all of France showing postcode areas. Now export that data to excel (5942 postcode areas in total) and cut and paste into your main excel workbook. You can now do the analysis independent of MP and get around the vagaries of the query methods on MP. If you set up another sheet called “Analysis” then my following feeble attempt at code would, I think, give you the area for a specified territory Code: Private Sub GetTerritoryArea_Click()
Dim TerritoryName As String, Postcode As String
Dim nCurrentRow As Integer, nRow1 As Integer, nRow2 As Integer, _
iCount As Integer, jCount As Integer
Dim R As Range
Dim Area As Single, TotalArea As Single
nCurrentRow = 2
Worksheets("Territory Definition").Cells(1, 4).Value = "Area"
Do While Worksheets("Territory Definition").Cells(nCurrentRow, 1) <> ""
Postcode = Worksheets("Territory Definition").Cells(nCurrentRow, 1).Value
Set R = Worksheets("Demographics").Range("A1:C5943").Find(Postcode)
If Not R Is Nothing Then Area = R.Offset(0, 2).Value
Worksheets("Territory Definition").Cells(nCurrentRow, 4).Value = Area
Set R = Nothing
nCurrentRow = nCurrentRow + 1
Loop
TerritoryName = InputBox("Which Territory?")
nCurrentRow = 2
TotalArea = 0#
Do While Worksheets("Territory Definition").Cells(nCurrentRow, 1) <> ""
If Worksheets("Territory Definition").Cells(nCurrentRow, 3).Value = TerritoryName _
Then TotalArea = TotalArea + Worksheets("Territory Definition"). _
Cells(nCurrentRow, 4).Value
nCurrentRow = nCurrentRow + 1
Loop
MsgBox "Area of " & TerritoryName & " is " & TotalArea
End Sub
Code: nRow1 = Worksheets("Territory Names").Cells(1, 1).End(xlDown).Row
nRow2 = Worksheets("Territory Definition").Cells(1, 1).End(xlDown).Row
iCount = 2
For iCount = 2 To nRow1
jCount = 2
TotalArea = 0#
For jCount = 2 To nRow2
If Worksheets("Territory Definition").Cells(jCount, 3).Value _
= Worksheets("Territory Names").Cells(iCount, 1).Value Then _
TotalArea = TotalArea + Worksheets("Territory Definition").Cells(jCount, 4).Value
Next jCount
Worksheets("Analysis").Cells(iCount, 1).Value = _
Worksheets("Territory Names").Cells(iCount, 1).Value
Worksheets("Analysis").Cells(iCount, 2).Value = TotalArea
Next iCount
Code: Private Sub TerritoryMap_Click()
Dim objApp As MapPoint.Application
Dim objMap As MapPoint.Map
Dim objDataSet1 As MapPoint.DataSet
Dim objDataSets As MapPoint.DataSets
Dim zDataSource1 As String
Set objApp = CreateObject("mappoint.application") ' Start Mappoint Europe 2006
Set objMap = objapp.ActiveMap
objApp.Visible = True
objApp.UserControl = True
Set objDataSets = objapp.ActiveMap.DataSets
zDataSource1 = "…… \FranceTerritories.xls!Territory Definition!"
Set objDataSet1 = objDataSets.ImportTerritories(zDataSource1, , geoCountryFrance, , geoImportExcelSheet)
objMap.DataSets.ZoomTo
End Sub
Rgds |
![]() |
| Tags |
| area, calculate, territory |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Show Postal code Area in existing territory file | Rubinho | MapPoint Desktop Discussion | 4 | 05-31-2007 06:54 AM |
| Calculate miles of roads in an area? | Anonymous | MapPoint Desktop Discussion | 0 | 12-02-2004 10:38 PM |
| Calculate distances | Anonymous | MapPoint Desktop Discussion | 1 | 11-18-2004 10:58 AM |
| gettign teh area inside a polygon or territory | Anonymous | MapPoint Desktop Discussion | 1 | 10-18-2003 05:21 PM |
| Calculate route | Anonymous | MapPoint Desktop Discussion | 0 | 07-03-2003 02:25 AM |