Example: Create Many Locations from a Drawing

Given a drawing of points, we quickly create a folder with Locations for all of the points, allowing us to quickly pan and zoom to a local view around each point.


This is an introductory example, so we will illustrate every small step.   That creates very many illustrations, but the actual process can be handled in around five minutes by someone familiar with Manifold.  It is a very easy process.


Download the project seen below, as it is at the end of the example, from create_locations_from_drawing.mxb (8 KB).

The Task

We have a map with a drawing layer that shows the locations of famous chateaux in France.  




The map has a Bing streets background layer and also Google and Bing satellite layers.




We can zoom in to the chateaux layer to see how this particular collection of chateaux is located in the valley of the river Loire.





Turning off the streets layer and turning on the Google satellite layer, we can see the points in the drawing layer in place over the satellite imagery.    We would like to zoom into various of the chateaux for a closer look.




We can always do that, to get a view like that above of the chateau at Chambord, by repeatedly using a right-click-and-drag to draw a zoom box.   However, even if we add a labels layer (not a bad idea in any event) to label the dots, it is still tedious to repeatedly use mouse motions to zoom in to get a view like that above.   If we want to see another chateau, we have to zoom back out and then repeat the process.


Much better would be to have a collection of locations, which would allow us to jump between views with a single click.    Our task is to create such a collection of locations automatically, one for each point record in our drawing.

Prepare the Table

Opening the drawing's table we see it is a typical table for a drawing, shown below in undocked form.




The table has a Name for each chateau, a geometry field called Geom that encodes the location, and a Description field that contains comments.    To automatically create a Location for each record in the table, we will use a script almost identical to that used in the Example: VBScript to Create Locations from a Table topic.




The text of the script illustrated above is:


' VBScript

Sub Main

        Set app = Manifold.Application

        Set db = app.GetDatabaseRoot() ' opened MAP file

        Set table = db.Search("locations")

        ' get list of records

        Set records = table.SearchAll(Array("Name", "Scale", "Longitude", "Latitude", "Description"))

        If (records Is Nothing) Then

                Exit Sub ' no records

        End If

        Do While records.Fetch

                ' read record values

                Set values = records.GetValues()

                name = values(0).Data

                scale = CDbl(values(1).Data)

                lon = CDbl(values(2).Data)

                lat = CDbl(values(3).Data)

                descr = values(4).Data

                ' compose location definition

                Set props = app.CreatePropertySet()

                props.SetProperty "Center", app.CreatePointObj(lon, lat)

                props.SetProperty "Scale", scale

                def = props.ToJson()

                ' create location

                created = db.Insert(name, "location")

                db.SetProperty created, "Text", def ' set location definition

                db.SetProperty created, "Folder", "Locations" ' put location into folder

                db.SetProperty created, "Description", descr ' set description

                app.Log "Created location: " & created


        ' app.OpenLog

End Sub


It is identical to the script used in the Example: VBScript to Create Locations from a Table topic, except that it requires the table to have a Description text field, from which the script pulls the text to place in the Description property of the Location component it will create.   Having a Description property in the Location component will cause Manifold to show that description text in a tool tip when the mouse hovers over the Location in the Project pane.   


Just like the script in the Example: VBScript to Create Locations from a Table topic, in addition to the required Description field,  the above script is hard-wired to require Name, Scale, Latitude, and Longitude fields in a table called locations.     We already have a Name field and a Description field, so with the focus on the table we will launch the Edit - Schema dialog to create Scale, Latitude, and Longitude fields in the table.




We add a Scale field that is type float64.  




We add a Latitude field that is a computed field, by choosing a type of float64 and in the Expression box entering the expression:


VectorValue(GeomCoordXY([Geom], 0),1)


For a discussion of how that expression works, see the Example: Create a Geocoded Table from a Drawing topic.




Next, we add a Longitude field that is a computed field, by choosing a type of float64 and in the Expression box entering the expression:


VectorValue(GeomCoordXY([Geom], 0),0)


See the Example: Create a Geocoded Table from a Drawing topic for how that expression works.




With the fields added that we want, we press OK.




The fields appear in the table.  We have adjusted column widths to enable them all to fit into the illustration.   The Latitude and Longitude fields are computed fields, automatically taking their values from whatever is in the Geom field.   We do that so if we edit the drawing by moving any of the points, the latitude and longitude values will automatically be recomputed.

Populate the Scale Field

Each record should have the desired Scale value.    We can fill the Scale field with a desired value using the Transform panel's Copy template, or we can use a quick trick.  Since this documentation is full of many examples using the Transform panel, we will use a quick trick, to show an alternative method.




We double-click into the Scale cell for any of the records and enter 3000 as the Scale.   Next we press Ctrl-A to select all records, or, we choose Edit - Select All.  




We right-click onto the cell that contains the 3000 value and choose Copy to Selection from the context menu.




Instantly, the Scale value for all selected records is set to 3000.  We press Ctrl-I to invert the selection, that is to select none, or, we choose Edit - Select None.  


Except for the name, the table we have prepared is ready to use with our script.

Make a Table Copy called "locations"

The script we will use is hard-wired to digest a table called locations, so we will make a copy of the table we have prepared and re-name the copy locations.




Click the table to highlight it and press Ctrl-C to copy, or, press the Copy icon, or, right-click the table and choose Copy.




Press Ctrl-V to paste, or press the Paste icon, or right-click onto a blank spot in the Project pane and choose Copy.   A copy of the table appears using a default name.




Rename the copy to locations by slow-double-clicking it, entering the new name, and then Enter.

Run the Script

We now have a table called locations that contains all of the fields required by the script.  Ready to go!




Right-click onto the Create Locations Description script and choose Run.





Instantly, a folder called Locations appears.   We can open it to see it contains a collection of locations, one for each record in our table.  Each location is named using the Name field for the record in the table.

Visit Locations

Now the fun part:  we can pan and zoom to any of the locations with a click.




The Locations button is loaded with all of the locations that are now in the project.   We can click on the Château d Amboise location to visit it.




The view instantly pans and zooms to that location, far faster than manually panning and zooming to Amboise.    If we position the mouse cursor over one of the locations we have created, a tooltip appears which gives the contents of the Description field.




If we right-click on one of the locations and choose Properties from the context menu, we can see the location has been created with a Description property that contains the text from the Description field in the table.   Adding a Description property is the difference between the Create Locations Description script used in this topic and the Create Locations script used in the Example: VBScript to Create Locations from a Table topic.




When there are many locations in a project, using the Locations button can become unwieldy.   We can always just right-click onto a desired location and choose View in Active Window.  




Above, we have instantly panned and zoomed to the Château d Angers.



See the Labels topic for a spectacular view of Chambord from ground level.   Visit France if you can, and spend a few days in the valley of the Loire visiting chateaux.


Download the project seen above, as it is at the end of the example, from create_locations_from_drawing.mxb (8 KB).

See Also

Getting Started


User Interface










Project Pane


Contents Pane


Contents - Select


Contents - Transform


Example: Locations - Save Locations and use saved Locations to quickly navigate to desired views in windows.


Example: Create a Table from Locations - Create a table that contains, as records, all of the Locations components in a project.  Each record contains the Name, Latitude, Longitude, and Scale of a location.  We use simple, point-and-click operations using the Select and Transform panels.


Example: Create a Geocoded Table from a Drawing - A partner example to Example: Create a Drawing from a Geocoded Table   A geocoded table has records with a latitude and longitude for each record.   This example starts with a table for a drawing of points where the geom field in the table contains geometry information for each point.   We extract the Y and X locations for each point  from the geom field to create latitude and longitude fields in the table for each record.


Example: VBScript to Create Locations from a Table - Use VBScript to take a table where each record has a name, scale, latitude and longitude and for each record create a Location component in the project.