record the two days of hard work, just come to the company less than a week, these days have been looking at GIS-related things.
First tune out the first android to call C + + code via JNI
And then it took two days to do an MFC read SHP format file with Mapwingis.ocx control
Hey... Looking back, this simple thing took two days, it's a waste of time.
No way, the novice on the road is not easy!
Reference Original: http://blog.csdn.net/clever101/article/details/5286575
The following document reads the operation of the SHP file:
Mapwingis is a good open source Component GIS project, the core of which is an ActiveX control named Mapwingis, which developers can use to add GIS-related features to their systems, such as map displays, plot points, lines, and graphs on layers , calculate length, access GIS data and other related work.
Original code Download: http://download.csdn.net/detail/liyuan_669/8129683
Programming Process: Mapwingis.ocx download
Register the Mapwingis ActiveX component. Run cmd: Enter regsvr32 C:\MapWinGIS.ocx (Note: C:\MapWinGIS.ocx is the absolute path that the mapwingis.ocx holds, change to its own path)
Start by using VS2010 to create a new single document project: MapGis, adding an MFC class for the control in an ActiveX control, such as:
Then select Map Control<1.0> in the registry, and add a CDMap0 class for interface _dmap, as follows:
Now start coding:
First open the stdafx.h, adding:
#import "C:\MapWinGIS\MapWinGIS.ocx" Rename_namespace ("Mapwindow") Rename ("GetObject", "Gisgetobject")
"C:\MapWinGIS\MapWinGIS.ocx" for Mapwingis.ocx decompression after the storage path, instead of their own can
In Resource.h, add a resource ID for the map window that you are about to create:
#define IDC_MAP 140
Add a CDMap0 private variable to the view class:
CDMap0 M_map;
Add a response function for the WM_CREATE message of the view class and dynamically create the map window with the following code:
Dynamically create Map window int cmapgisview::oncreate (lpcreatestruct lpcreatestruct) {if (cview::oncreate (lpcreatestruct) = =-1) return -1;//TODO: Add your dedicated creation code CRect RCMAP here; GetClientRect (Rcmap); M_map.create (null,ws_child| ws_visible| WS_BORDER,RCMAP,THIS,IDC_MAP); return 0;}
Add a response function for the wm_size message of the view class, adding the following code to make the map control fill the entire view:
void Cmapgisview::onsize (UINT nType, int cx, int cy) {cview::onsize (NType, CX, CY);//TODO: Add Message Handler code here if (M_map.m_hwnd = = NULL) return; if (IsWindow (M_map.m_hwnd))//Determines whether the given window handle identifies an existing window {CRect rc;this->getclientrect (&RC); M_map.movewindow ( &rc,false); M_map.zoomtoprev (); }}
Add a private variable of type CString in the view class M_strfilepath is used to save the path to the TIF image or shp file, and then add a command message function to the view class for the menu "open": OnFileOpen:
CString M_strfilepath;
The code for the OnFileOpen function is as follows:
void Cmapgisview::onfileopen () {//TODO: Add Command handler code here TCHAR szfilters[]= _t ("SHP Files (*.shp) |*.shp| |"); CFileDialog Filedlg (true,_t ("shp"), _t ("*.shp"), Ofn_filemustexist | Ofn_hidereadonly, Szfilters, this); if (filedlg.domodal () = = IDOK) {M_strfilepath = Filedlg.getpathname (); if (_t ("")!=m_ strFilePath) {//delete all layers first m_map.removealllayers ();//Create SHP interface open SHP file add map mapwindow::ishapefileptr pshapefilebound; Pshapefilebound.createinstance (__uuidof (mapwindow::shapefile));p Shapefilebound->open (_bstr_t (M_strFilePath) , false); M_map.addlayer (pshapefilebound,true);} Send view Redraw message invalidate ();}}
The program runs as follows:
National Map SHP 1:4 million downloads
Open shp file:
MFC reads SHP files through the Mapwingis control