C # Develop GIS Application Concise Tutorial (3)

xiaoxiao2021-03-05  27

Chapter III Data Processing

Before introducing the data processing, let's generate your own map in MapInfo, which will all be generated in this chapter. This is because MapX itself provides a large difference in data structure. Not suitable for introducing data processing of MAPX.

First install MapInfo, it is best to use a version of 7.0. The following is done under the MapInfo Professional version 7.0.

Open MapInfo, the interface is as follows:

Click on the leftmost of the toolbar

Button, create a new layer data table. As shown below:

In the "New Table" window, follow the "CREATE ..." button to create a new data layer. MapInfo will pop up a window, as shown below:

Set the field properties of the data table in this window. Click the "Add Field" button to add the field to the table, we will add 4 fields here: ID, name, monthly supply period and water charges. Set good fields As shown below:

After setting up, click the "Create ..." button, mapinfo will ask the file path to establish a layer table. Change your layer table file name to "HouseLayer.Tab", store it under the appropriate path. For example: "E: / test / datamap /".

After saving, get a blank layer table file, MapInfo opened this file as follows:

This layer has no graphics on the table, we add two primitives on the layer and add the data.

Select a rectangular tool on the Drawing tool strip, draw a rectangle on the Houselayer Map, then use the copy paste to copy it to another rectangle.

After selecting the primitive, it is slightly modified for two primitives. As shown below:

Now, a simple mapping is completed.

Then enter the data related to the graphics. Select the button indicated below to select the chamfer on the layer, open the window of the input data.

Enter the following two data in the window input data:

ID Name Moon Year Hydroelectric Test 0001A Building 2518.770002B 3025.12

Save the layer. MapInfo's drawing work is completed.

You also need to bring the justified layer in a map file (.GST format) in the tool GEOSet Manager that comes with the Mapx 5.0, you can call this file "Community .GST" by Mapx.

Ok, prepare for work, now we start to introduce data processing of MapX.

Data Reading

Pioneing the functionality of the program: Place the community map on the MAPX control, and place a listView on the left side of the window, displaying all the chammet data in all Houselayer layers tables in this listView.

Unlike the past, our program interface has made some changes to track data changes.

The picture below is the window design interface:

It can be seen that we placed a ListView control on the left side and add 4 columns (columns) to display data in listView. At the same time, the map of the MAPX control has been made to the "Community" map made by our own.

Write the following code in Button1_Click in Button1:

MapXLib.Fields flds = new MapXLib.FieldsClass (); MapXLib.Layer lyr = axMap1.Layers._Item ( "HouseLayer"); MapXLib.Dataset dts = null; flds.Add ( "ID", "ID", MapXLib.AggregationFunctionConstants .miAggregationSum, MapXLib.FieldTypeConstants.miTypeString); flds.Add ( "name", "name", MapXLib.AggregationFunctionConstants.miAggregationSum, MapXLib.FieldTypeConstants.miTypeString); flds.Add ( "March for life", "month for life." , MapXLib.AggregationFunctionConstants.miAggregationSum, MapXLib.FieldTypeConstants.miTypeInteger); flds.Add ( "utilities", "utilities", MapXLib.AggregationFunctionConstants.miAggregationSum, MapXLib.FieldTypeConstants.miTypeFloat); dts = axMap1.DataSets.Add (MapXLib .Datasettypeconstants.midatasetlayer, lyr, lyr.name, 0, 0, 0, flds, false; listview1.items.clear (); for (int i = 1; i <= dts.rowcount; i ) {listview1.items .Add (New String [] {DTS [i, 1] .tostring (), DTS [i, 2] .tostring (), DTS [i, 3] .tostring (), DTS [i, 4] .tostring ()});} AXMAP1.DataSets.removeAll (); code is still very short, is further deepening to the previous introduction knowledge. It should be noted here is the application of DTS. Run It can be seen that the program is properly read correctly.

At the end of the program, we removed all the DataSets in the MAPX control, which is convenient to use DataSets later.

2. Add data (data address)

Adding data on the layer table is actually added, but this element is data information.

Still using an example of reading data, we add a button button2 on the window to write it, click the event code button2_click as follows:

MapXLib.Feature ftr = new MapXLib.FeatureClass (); MapXLib.Points pts = new MapXLib.PointsClass (); MapXLib.Point pt = new MapXLib.PointClass (); MapXLib.RowValues ​​rvs = new MapXLib.RowValuesClass (); MapXLib. Fields flds = new MapXLib.FieldsClass (); MapXLib.Layer lyr = axMap1.Layers._Item ( "HouseLayer"); MapXLib.Dataset dts = null; flds.Add ( "ID", "ID", MapXLib.AggregationFunctionConstants.miAggregationSum , MapXLib.FieldTypeConstants.miTypeString); flds.Add ( "name", "name", MapXLib.AggregationFunctionConstants.miAggregationSum, MapXLib.FieldTypeConstants.miTypeString); flds.Add ( "March for life", "month for life", MapXLib .AggregationFunctionConstants.miAggregationSum, MapXLib.FieldTypeConstants.miTypeInteger); flds.Add ( "utilities", "utilities", MapXLib.AggregationFunctionConstants.miAggregationSum, MapXLib.FieldTypeConstants.miTypeFloat); dts = axMap1.DataSets.Add (MapXLib.DatasetTypeConstants .midatasetlayer, lyr, lyr.name, 0,0,0,0, flds, false; rvs = dts.get_rowvalues ​​(0); RVS._Item ("ID"). Value = "0003"; rvs._item ("name ") .Value =" c "; rvs._item (" month supply years ") .value = 20; rvs._item (" water electricity fee ") .valu e = 21.73; ftr.Attach (axMap1.GetOcx ()); ftr.Style = axMap1.Layers._Item ( "HouseLayer") Style;. ftr.Style.RegionPattern = MapXLib.FillPatternConstants.miPatternSolid; ftr.Style.RegionColor = 16711680; ftr.type = Mapxlib.featureTypeConstants.mifeatureTypeRegion; Pt.Set (1, 1); PTS.Add (Pt, 1); Pt.Set (2, 1); PTS.Add (PT, 2); PT. Set (2, 2); PTS.Add (PT, 3); Pt.Set (1, 2); PTS.Add (PT, 4); FTR = AXMAP1.FEATUREFAACTORY.CREATEREGON (PTS, FTR.Style); FTR = AXMAP1.LAYERS._ITEM ("Houselayer"). Addfeature (FTR, RVS); FTR.UPDATE (FTR, RVS); Axmap1.DataSets.RemoveAll ();

In the above program we implemented a new element to the layer table, the data information of this primitive is as follows: ID name monthly supply year water electricity cost 0003c building 2021.73

It should be noted that we first use DataSets.Add to read the data, and then get the row data structure using GET_ROWVALUES, and then the assignment of the data.

Run the program, click Button1, you can see only two records in the left ListView, then click Button2, see a blue rectangular chamber on the layer, which is the dimension of our increased data, Click Button1, you can see that the data information of the newly added element appears in the left ListView.

3. Modify data (data modify)

Now, add another button button3 in the window. This button is to be implemented to change the name of "A" to "A1". That is, we have to modify the data of the A, this button The code is as follows:

MapXLib.FindFeature ftrRes = null; MapXLib.Points pts = new MapXLib.PointsClass (); MapXLib.Point pt = new MapXLib.PointClass (); MapXLib.RowValues ​​rvs = new MapXLib.RowValuesClass (); MapXLib.Fields flds = new MapXLib .Fieldsclass (); mapxlib.layer lyr = axmap1.layers._item ("houselayer"); Mapxlib.DataSet DTS = null; ftrres = axmap1.layers._item ("houselayer"). Find.search ("0001", " "); if (ftrres.findrc% 10 == 1) {flds.add (" id "," id ", mapxlib.aggregationFunctionConstants.miaggregationSum, Mapxlib.fieldTypeConstants.mitypeString); FLDS.Add (" Name ", Name ", MapXLib.AggregationFunctionConstants.miAggregationSum, MapXLib.FieldTypeConstants.miTypeString); flds.Add (" March for life "," month for life ", MapXLib.AggregationFunctionConstants.miAggregationSum, MapXLib.FieldTypeConstants.miTypeInteger); flds.Add (" hydro fee "and" utilities ", MapXLib.AggregationFunctionConstants.miAggregationSum, MapXLib.FieldTypeConstants.miTypeFloat); dts = axMap1.DataSets.Add (MapXLib.DatasetTypeConstants.miDataSetLayer, lyr, lyr.Name, 0,0,0, flds, false ); For (int I = 0; i

4. Delete data (Data deletion)

Deleting the data is actually deleted, as long as the element is found, it can be deleted directly. But attention is that because the primitive contains the data, it is also a tightening table after deleting the data. It is also very simple in the tightening table.

Still using our previous example, add a Button4, write code in its clicking event as follows:

Mapxlib.Findfeature Ftrres = null; ftrres = axmap1.layers._item ("houselayer"). Find.Search ("0003", "); if (ftrres.findrc% 10 == 1) {AXMAP1.LAYERS._ITEM "Houselayer"). Deletefeature (ftrres);} // Tightened table AXMAP1.LAYERS._ITEM ("Houselayer"). Pack (MapxLib.LayerPackConstant.miPackall); If there is no tightening table after deleting the chamber, click Button1, You will see a blank data in ListView.

The data processing techniques described in this chapter are reproduced in alive. There are still important contents about data processing, such as special maps, etc., will be described in later chapters.

Exercise:

1. Read all the chammers of the Houselayer in the DataGrid and update the data modified within the DataGrid to the layer table.

2. Use custom tools to increase and delete primitives with data.

转载请注明原文地址:https://www.9cbs.com/read-36247.html

New Post(0)