📄 mapperseis.cpp
字号:
// MapperSeis.cpp: implementation of the CMapperSeis class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "mapper.h"
#include "MapperSeis.h"
#include "graphseiadddlg.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMapperSeis::CMapperSeis()
{
}
CMapperSeis::~CMapperSeis()
{
}
void CMapperSeis::Create(CMap1 &map)
{
DeleteAll();
//标注EQ3格式地震目录,地震点大小根据震级变化
//如果使用其他格式,需要先转换成eq3
CGraphSeiAddDlg sad;
sad.m_lSum=0;
if(sad.DoModal()!=IDOK)
return;
m_crFill=sad.m_oColorFill.GetColor();
m_crOutline=sad.m_oColorOutline.GetColor();
m_nParaType=sad.m_nParaType;
m_nSymbol=sad.m_nSymbol;
m_bOutline=sad.m_bOutline;
long i,count;
count=sad.m_Sei.GetSize();
short mag;
for(i=0;i<count;i++)
{
if(!sad.m_Sei[i].bView)
continue;
CMoPoint* pt = new CMoPoint(); //map.ToMapPoint((float)X, (float)Y)
pt->CreateDispatch(TEXT("MapObjects2.Point"));
pt->SetX(sad.m_Sei[i].lon);
pt->SetY(sad.m_Sei[i].lat);
mag=(short)sad.m_Sei[i].mag;
if(mag>2.0)
m_iaSize.Add((int)(mag*1.5));
else
m_iaSize.Add(3);
if (LPDISPATCH(pt))
m_oaPoints.Add(pt);
}
m_taSei.RemoveAll();
m_taSei.InsertAt(0,&sad.m_Sei);
}
void CMapperSeis::DeleteAll()
{
for (int i = 0; i < m_oaPoints.GetSize(); i++)
{
m_oaPoints[i]->ReleaseDispatch();
delete m_oaPoints[i];
}
m_oaPoints.RemoveAll();
}
void CMapperSeis::Draw(CMap1 &map)
{
long i;
CMoSymbol sym;
sym.CreateDispatch(TEXT("MapObjects2.Symbol"));
sym.SetSymbolType(moPointSymbol);
sym.SetOutline(m_bOutline);
sym.SetOutlineColor(m_crOutline);
sym.SetStyle(m_nSymbol);
sym.SetColor(m_crFill);
for (i = 0; i < m_oaPoints.GetSize(); i++)
{
sym.SetSize(m_iaSize[i]);
map.DrawShape(*m_oaPoints[i], sym);
}
}
BOOL CMapperSeis::ExportShp(CMap1 &map,CString sPathFile)
{
CMoDataConnection conn;
if (!conn.CreateDispatch(TEXT("MapObjects2.DataConnection")))
return FALSE;
conn.SetDatabase(GetFileDirectory(sPathFile));
if (!conn.Connect())
return FALSE;
CMoTableDesc tableDesc;
if (!tableDesc.CreateDispatch(TEXT("MapObjects2.TableDesc")))
return FALSE;
tableDesc.SetFieldCount(7);
tableDesc.SetFieldName(0, TEXT("日期"));
tableDesc.SetFieldType(0, moLong);
tableDesc.SetFieldLength(0, 8);
tableDesc.SetFieldPrecision(0, 8);
tableDesc.SetFieldScale(0, 0); // decimal places
tableDesc.SetFieldName(1, TEXT("时间"));
tableDesc.SetFieldType(1, moLong);
tableDesc.SetFieldLength(1, 8);
tableDesc.SetFieldPrecision(1, 8);
tableDesc.SetFieldScale(1, 0); // decimal places
tableDesc.SetFieldName(2, TEXT("纬度"));
tableDesc.SetFieldType(2, moDouble);
tableDesc.SetFieldPrecision(2, 15);
tableDesc.SetFieldScale(2, 4); // decimal places
tableDesc.SetFieldName(3, TEXT("经度"));
tableDesc.SetFieldType(3, moDouble);
tableDesc.SetFieldPrecision(3, 15);
tableDesc.SetFieldScale(3, 4); // decimal places
tableDesc.SetFieldName(4, TEXT("震级"));
tableDesc.SetFieldType(4, moDouble);
tableDesc.SetFieldPrecision(4, 15);
tableDesc.SetFieldScale(4, 4); // decimal places
tableDesc.SetFieldName(5, TEXT("深度"));
tableDesc.SetFieldType(5, moDouble);
tableDesc.SetFieldPrecision(5, 15);
tableDesc.SetFieldScale(5, 4); // decimal places
tableDesc.SetFieldName(6, TEXT("地点"));
tableDesc.SetFieldType(6, moString);
tableDesc.SetFieldLength(6, 16);
VARIANT va;
VariantInit(&va);
va.vt = VT_BOOL;
va.boolVal = false;
CMoGeoDataset geoDataset(conn.AddGeoDataset(GetFileTitle(sPathFile), moPoint, tableDesc, va ,va));
ASSERT(LPDISPATCH(geoDataset));
CMoMapLayer layer;
if (!layer.CreateDispatch(TEXT("MapObjects2.MapLayer")))
return FALSE;
layer.SetGeoDataset(geoDataset);
CMoRecordset recs(layer.GetRecords());
CMoFields fields(recs.GetFields());
CMoPoint pt;
CString s;
long date,time;
for (long i = 0; i < m_taSei.GetSize(); i++)
{
if(!m_taSei[i].bView)
continue;
pt.CreateDispatch(TEXT("MapObjects2.Point"));
pt.SetX(m_taSei[i].lon);
pt.SetY(m_taSei[i].lat);
recs.AddNew();
SetValue(fields, TEXT("Shape"), LPDISPATCH(pt));
date=(long)m_taSei[i].dt.GetYear()*10000L+
(long)m_taSei[i].dt.GetMonth()*100L+(long)m_taSei[i].dt.GetDay();
time=(long)m_taSei[i].dt.GetHour()*10000L+
(long)m_taSei[i].dt.GetMinute()*100L+(long)m_taSei[i].dt.GetSecond();
SetValue(fields, TEXT("日期"), date);
SetValue(fields, TEXT("时间"), time);
SetValue(fields, TEXT("纬度"), m_taSei[i].lat);
SetValue(fields, TEXT("经度"), m_taSei[i].lon);
SetValue(fields, TEXT("震级"), m_taSei[i].mag);
SetValue(fields, TEXT("深度"), m_taSei[i].depth);
SetValue(fields, TEXT("地点"), m_taSei[i].szPlace);
recs.Update();
pt.ReleaseDispatch();
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -