Exemplo n.º 1
0
void CookieCutter::cut(OsmMapPtr cutterShapeMap, OsmMapPtr doughMap)
{
  OGREnvelope env = cutterShapeMap->calculateBounds();
  env.Merge(doughMap->calculateBounds());

  // reproject the dough and cutter into the same planar projection.
  MapReprojector::reprojectToPlanar(doughMap, env);
  MapReprojector::reprojectToPlanar(cutterShapeMap, env);

  // create a complex geometry representing the alpha shape
  UnionPolygonsVisitor v;
  cutterShapeMap->visitRo(v);
  shared_ptr<Geometry> cutterShape = v.getUnion();

  if (_outputBuffer != 0.0)
  {
    cutterShape.reset(cutterShape->buffer(_outputBuffer));
  }

  if (cutterShape->getArea() == 0.0)
  {
    LOG_WARN("Cutter area is zero. Try increasing the buffer size or check the input.");
  }

  // free up a little RAM
  cutterShapeMap.reset();
  // remove the cookie cutter portion from the "dough"
  // if crop is true, then the cookie cutter portion is kept and the "dough" is dropped.
  MapCropper::crop(doughMap, cutterShape, !_crop);
  // clean up any ugly bits left over
  SuperfluousWayRemover::removeWays(doughMap);
  SuperfluousNodeRemover::removeNodes(doughMap);
}
Exemplo n.º 2
0
void wxGISMapView::PanStop(wxPoint MouseLocation)
{
    ReleaseMouse();

	wxCoord x =  m_StartMouseLocation.x - MouseLocation.x;
	wxCoord y =  m_StartMouseLocation.y - MouseLocation.y;

	wxRect rect = m_pGISDisplay->GetDeviceFrame();//GetClientRect();
	if(x == 0 && y == 0)
	{
		x = m_StartMouseLocation.x - (rect.GetLeft() + rect.GetWidth() / 2);
		y = m_StartMouseLocation.y - (rect.GetTop() + rect.GetHeight() / 2);
	}
	rect.Offset(x, y);

	if(m_pGISDisplay)
	{
		OGREnvelope Env = m_pGISDisplay->TransformRect(rect);

		//set clip geom
		//FillClipGeometry(GetClientRect(), x, y);

		if(Env.IsInit())//set new bounds
			Do(Env);
		m_nDrawingState = enumGISMapDrawing;
	}
}
Exemplo n.º 3
0
Arquivo: map.cpp Projeto: jacklibj/r5
OGREnvelope wxGISMap::GetFullExtent(void)
{
	OGREnvelope res;
	for(size_t i = 0; i < m_Layers.size(); i++)
		//check if the spatial ref is same!!!
		res.Merge(*m_Layers[i]->GetEnvelope());
	return res;
}
Exemplo n.º 4
0
 std::unique_ptr<OGRMultiPolygon> create_multipolygon(const osmium::Area& area) {
     std::unique_ptr<OGRMultiPolygon> geom = m_factory.create_multipolygon(area);
     OGREnvelope env;
     geom->getEnvelope(&env);
     m_envelope.Merge(env);
     return geom;
 }
Exemplo n.º 5
0
 std::unique_ptr<OGRLineString> create_linestring(const osmium::Way& way) {
     std::unique_ptr<OGRLineString> geom = m_factory.create_linestring(way);
     OGREnvelope env;
     geom->getEnvelope(&env);
     m_envelope.Merge(env);
     return geom;
 }
Exemplo n.º 6
0
 std::unique_ptr<OGRPoint> create_point(const osmium::Node& node) {
     std::unique_ptr<OGRPoint> geom = m_factory.create_point(node);
     OGREnvelope env;
     geom->getEnvelope(&env);
     m_envelope.Merge(env);
     return geom;
 }
Exemplo n.º 7
0
bool wxGISDisplay::CanDraw(OGREnvelope &Env)
{
	if(!IsDoubleEquil(m_dAngleRad, 0.0))
	{
		RotateEnvelope(Env, -m_dAngleRad, m_dRotatedBoundsCenterX, m_dRotatedBoundsCenterY);
	}

	return Env.Contains(m_CurrentBoundsRotated) || m_CurrentBoundsRotated.Contains(Env) || Env.Intersects(m_CurrentBoundsRotated);
}
Exemplo n.º 8
0
void wxGISMapView::OnMouseWheel(wxMouseEvent& event)
{
	//event.Skip(false);
    DestroyDrawThread();

	int nDirection = event.GetWheelRotation();
	int nDelta = event.GetWheelDelta();
	int nFactor = nDirection / nDelta;
	m_nDrawingState = enumGISMapWheeling;

	m_nFactor += ZOOM_FACTOR * (double)nFactor;


	if(m_pGISDisplay)
	{
		double dZoom = 1;
		if(m_nFactor < 0)
			dZoom = fabs(1.0 / (m_nFactor - 1));
		else if(m_nFactor > 0)
			dZoom = 1 + m_nFactor;
        wxClientDC CDC(this);
		m_pGISDisplay->WheelingDraw(dZoom, &CDC);

		//draw scale text
		OGREnvelope Env = CreateEnvelopeFromZoomFactor(dZoom);
		if(Env.IsInit())
		{
			double sScale = GetScaleRatio( Env, CDC );
			wxString sFormatScale = NumberScale(sScale);
			sFormatScale.Prepend(wxT("1 : "));
			DrawToolTip(CDC, sFormatScale);
		}
	}

	//if(!m_timer.IsRunning())
		m_timer.Start(TM_WHEELING);
}
Exemplo n.º 9
0
void wxAxIdentifyView::OnMenu(wxCommandEvent& event)
{
	wxTreeItemId TreeItemId = m_pTreeCtrl->GetSelection();
    wxIdentifyTreeItemData* pData = (wxIdentifyTreeItemData*)m_pTreeCtrl->GetItemData(TreeItemId);
    if(pData == NULL)
		return;

	switch(event.GetId())
	{
	case ID_WGMENU_FLASH:
	{
        if (pData->m_Geometry.IsOk())
        {
            m_pMapView->AddFlashGeometry(pData->m_Geometry, GetDrawSymbol(pData->m_Geometry.GetType()));
        }
		else
		{
            wxTreeItemIdValue cookie;
			for ( wxTreeItemId item = m_pTreeCtrl->GetFirstChild(TreeItemId, cookie); item.IsOk(); item = m_pTreeCtrl->GetNextChild(TreeItemId, cookie) )
			{
				pData = (wxIdentifyTreeItemData*)m_pTreeCtrl->GetItemData(item);
                if (pData)
                {
                    m_pMapView->AddFlashGeometry(pData->m_Geometry, GetDrawSymbol(pData->m_Geometry.GetType()));
                }
			}
		}
        m_pMapView->StartFlashing();
	}
	break;
	case ID_WGMENU_PAN:
	{
        wxGISGeometryArray Arr;
		if(pData->m_Geometry.IsOk())
        {
            m_pMapView->AddFlashGeometry(pData->m_Geometry, GetDrawSymbol(pData->m_Geometry.GetType()));
            Arr.Add(pData->m_Geometry);
        }
		else
		{
            wxTreeItemIdValue cookie;
			for ( wxTreeItemId item = m_pTreeCtrl->GetFirstChild(TreeItemId, cookie); item.IsOk(); item = m_pTreeCtrl->GetNextChild(TreeItemId, cookie) )
			{
				pData = (wxIdentifyTreeItemData*)m_pTreeCtrl->GetItemData(item);
				if(pData)
                {
                    m_pMapView->AddFlashGeometry(pData->m_Geometry, GetDrawSymbol(pData->m_Geometry.GetType()));
                    Arr.Add(pData->m_Geometry);
                }
			}
		}

        if(Arr.IsEmpty())
            return;

		OGREnvelope Env;
		for(size_t i = 0; i < Arr.GetCount(); ++i)
		{
            OGREnvelope TempEnv = Arr[i].GetEnvelope();
			Env.Merge(TempEnv);
		}
		OGREnvelope CurrentEnv = m_pMapView->GetCurrentExtent();
		MoveEnvelope(CurrentEnv, Env);
		m_pMapView->Do(CurrentEnv);
        m_pMapView->StartFlashing();
	}
	break;
	case ID_WGMENU_ZOOM:
	{
        wxGISGeometryArray Arr;

		if(pData->m_Geometry.IsOk())
        {
            m_pMapView->AddFlashGeometry(pData->m_Geometry, GetDrawSymbol(pData->m_Geometry.GetType()));
            Arr.Add(pData->m_Geometry);
        }
		else
		{
			wxTreeItemIdValue cookie;
			for ( wxTreeItemId item = m_pTreeCtrl->GetFirstChild(TreeItemId, cookie); item.IsOk(); item = m_pTreeCtrl->GetNextChild(TreeItemId, cookie) )
			{
				pData = (wxIdentifyTreeItemData*)m_pTreeCtrl->GetItemData(item);
				if(pData)
                {
                    m_pMapView->AddFlashGeometry(pData->m_Geometry, GetDrawSymbol(pData->m_Geometry.GetType()));
                    Arr.Add(pData->m_Geometry);
                }
			}
		}

        if(Arr.IsEmpty())
            return;

		OGREnvelope Env;
		for(size_t i = 0; i < Arr.GetCount(); ++i)
		{
			OGREnvelope TempEnv = Arr[i].GetEnvelope();
			Env.Merge(TempEnv);
		}
		m_pMapView->Do(Env);
        m_pMapView->StartFlashing();
	}
	break;
	default:
	break;
	}
}
Exemplo n.º 10
0
void wxGISMapView::OnTimer( wxTimerEvent& event )
{
    //event.Skip();
    //wxSafeYield(this, true);
#ifdef __WXGTK__
    wxWakeUpIdle();
#endif

    switch(m_nDrawingState)
    {
    case enumGISMapZooming:
    {
        //stop zooming action
		if(m_pGISDisplay && !wxGetMouseState().LeftIsDown()) //user release mouse button, so draw contents
		{
		    wxRect rc = GetClientRect();
        	m_pGISDisplay->SetDeviceFrame(rc);
			m_pGISDisplay->SetDerty(true);
			m_nDrawingState = enumGISMapDrawing;
            CreateAndRunDrawThread();
			//wxCommandEvent evt(wxEVT_COMMAND_STARTDRAWING);wxEVT_COMMAND_DATA_SENT
			//GetEventHandler()->ProcessEvent( evt );

//                if(!m_pMapDrawingThread)//m_nDrawingState = enumGISMapDrawing
//                {
//                    StartDraingThread();
//                }
            m_timer.Stop();	//Thaw();
		}
    }
    break;
    case enumGISMapWheeling:
		m_nDrawingState = enumGISMapWheelingStop;
		return;
    case enumGISMapWheelingStop:
		//stop wheeling action
		if(m_pGISDisplay)
		{
			double dZoom = 1;
			if(m_nFactor < 0)
				dZoom = fabs(1.0 / (m_nFactor - 1));
			else if(m_nFactor > 0)
				dZoom = 1 + m_nFactor;

			OGREnvelope Env = CreateEnvelopeFromZoomFactor(dZoom);
			if(Env.IsInit())//set new bounds
				Do(Env);
			m_nDrawingState = enumGISMapDrawing;
		}
		m_nFactor = 0;
		m_timer.Stop();
		return;
    break;
    case enumGISMapFlashing:
        if(m_staFlashGeoms.empty())
        {
            m_nDrawingState = enumGISMapDrawing;
            m_pGISDisplay->SetDrawCache(m_pGISDisplay->GetLastCacheID(), true);
		    m_timer.Stop();
        }
        else
        {
            Flash(m_eFlashStyle);
        }
    break;
    case enumGISMapDrawing:
        break;//not stop timer
    case enumGISMapNone:
    default:
		m_timer.Stop();
    break;
    };
	Refresh();
}
Exemplo n.º 11
0
bool wxGISDrawingLayer::Draw(wxGISEnumDrawPhase DrawPhase, ITrackCancel* const pTrackCancel)
{
    wxCHECK_MSG(m_pDisplay, false, wxT("Display pointer is NULL"));

    wxCriticalSectionLocker lock(m_CritSect);

    OGREnvelope stDisplayExtentRotated = m_pDisplay->GetBounds(true);
    OGREnvelope stFeatureDatasetExtentRotated = m_oLayerExtent;

    //rotate featureclass extent
    if (!IsDoubleEquil(m_pDisplay->GetRotate(), 0.0))
    {
        wxRealPoint dfCenter = m_pDisplay->GetBoundsCenter();
        RotateEnvelope(stFeatureDatasetExtentRotated, m_pDisplay->GetRotate(), dfCenter.x, dfCenter.y);//dCenterX, dCenterY);
    }

    //if envelopes don't intersect exit
    if (!stDisplayExtentRotated.Intersects(stFeatureDatasetExtentRotated))
        return false;

    //get intersect envelope to fill vector data
    OGREnvelope stDrawBounds = stDisplayExtentRotated;
    stDrawBounds.Intersect(stFeatureDatasetExtentRotated);
    if (!stDrawBounds.IsInit())
        return false;

    IProgressor* pProgress = NULL;
    if (NULL != pTrackCancel)
    {
        pProgress = pTrackCancel->GetProgressor();
    }

    if (NULL != pProgress)
    {
        pProgress->SetRange(m_aoShapes.size());
    }

    //draw shapes
    for (size_t i = 0; i < m_aoShapes.size(); ++i)
    {
        if (NULL != pProgress)
        {
            pProgress->SetValue(i);
        }

        if (pTrackCancel != NULL && !pTrackCancel->Continue())
            return true;
        if (m_aoShapes[i] != NULL)
        {
            m_aoShapes[i]->Draw(m_pDisplay);
        }
    }

    //draw enumGISShapeStateSelected

    //draw enumGISShapeStateRotated

    //draw enumGISShapeStatePoints

    return true;
}
Exemplo n.º 12
0
OGRErr PDFWritableVectorDataset::SyncToDisk()
{
    if (nLayers == 0 || !bModified)
        return OGRERR_NONE;

    bModified = FALSE;

    OGREnvelope sGlobalExtent;
    int bHasExtent = FALSE;
    for(int i=0;i<nLayers;i++)
    {
        OGREnvelope sExtent;
        if (papoLayers[i]->GetExtent(&sExtent) == OGRERR_NONE)
        {
            bHasExtent = TRUE;
            sGlobalExtent.Merge(sExtent);
        }
    }
    if (!bHasExtent ||
        sGlobalExtent.MinX == sGlobalExtent.MaxX ||
        sGlobalExtent.MinY == sGlobalExtent.MaxY)
    {
        CPLError(CE_Failure, CPLE_AppDefined,
                 "Cannot compute spatial extent of features");
        return OGRERR_FAILURE;
    }

    PDFCompressMethod eStreamCompressMethod = COMPRESS_DEFLATE;
    const char* pszStreamCompressMethod = CSLFetchNameValue(papszOptions, "STREAM_COMPRESS");
    if (pszStreamCompressMethod)
    {
        if( EQUAL(pszStreamCompressMethod, "NONE") )
            eStreamCompressMethod = COMPRESS_NONE;
        else if( EQUAL(pszStreamCompressMethod, "DEFLATE") )
            eStreamCompressMethod = COMPRESS_DEFLATE;
        else
        {
            CPLError( CE_Warning, CPLE_NotSupported,
                    "Unsupported value for STREAM_COMPRESS.");
        }
    }

    const char* pszGEO_ENCODING =
        CSLFetchNameValueDef(papszOptions, "GEO_ENCODING", "ISO32000");

    double dfDPI = CPLAtof(CSLFetchNameValueDef(papszOptions, "DPI", "72"));
    if (dfDPI < 72.0)
        dfDPI = 72.0;

    const char* pszNEATLINE = CSLFetchNameValue(papszOptions, "NEATLINE");

    int nMargin = atoi(CSLFetchNameValueDef(papszOptions, "MARGIN", "0"));

    PDFMargins sMargins;
    sMargins.nLeft = nMargin;
    sMargins.nRight = nMargin;
    sMargins.nTop = nMargin;
    sMargins.nBottom = nMargin;

    const char* pszLeftMargin = CSLFetchNameValue(papszOptions, "LEFT_MARGIN");
    if (pszLeftMargin) sMargins.nLeft = atoi(pszLeftMargin);

    const char* pszRightMargin = CSLFetchNameValue(papszOptions, "RIGHT_MARGIN");
    if (pszRightMargin) sMargins.nRight = atoi(pszRightMargin);

    const char* pszTopMargin = CSLFetchNameValue(papszOptions, "TOP_MARGIN");
    if (pszTopMargin) sMargins.nTop = atoi(pszTopMargin);

    const char* pszBottomMargin = CSLFetchNameValue(papszOptions, "BOTTOM_MARGIN");
    if (pszBottomMargin) sMargins.nBottom = atoi(pszBottomMargin);

    const char* pszExtraImages = CSLFetchNameValue(papszOptions, "EXTRA_IMAGES");
    const char* pszExtraStream = CSLFetchNameValue(papszOptions, "EXTRA_STREAM");
    const char* pszExtraLayerName = CSLFetchNameValue(papszOptions, "EXTRA_LAYER_NAME");

    const char* pszOGRDisplayField = CSLFetchNameValue(papszOptions, "OGR_DISPLAY_FIELD");
    const char* pszOGRDisplayLayerNames = CSLFetchNameValue(papszOptions, "OGR_DISPLAY_LAYER_NAMES");
    int bWriteOGRAttributes = CSLFetchBoolean(papszOptions, "OGR_WRITE_ATTRIBUTES", TRUE);
    const char* pszOGRLinkField = CSLFetchNameValue(papszOptions, "OGR_LINK_FIELD");

    const char* pszOffLayers = CSLFetchNameValue(papszOptions, "OFF_LAYERS");
    const char* pszExclusiveLayers = CSLFetchNameValue(papszOptions, "EXCLUSIVE_LAYERS");

    const char* pszJavascript = CSLFetchNameValue(papszOptions, "JAVASCRIPT");
    const char* pszJavascriptFile = CSLFetchNameValue(papszOptions, "JAVASCRIPT_FILE");

/* -------------------------------------------------------------------- */
/*      Create file.                                                    */
/* -------------------------------------------------------------------- */
    VSILFILE* fp = VSIFOpenL(GetDescription(), "wb");
    if( fp == NULL )
    {
        CPLError( CE_Failure, CPLE_OpenFailed,
                  "Unable to create PDF file %s.\n",
                  GetDescription() );
        return OGRERR_FAILURE;
    }

    GDALPDFWriter oWriter(fp);

    double dfRatio = (sGlobalExtent.MaxY - sGlobalExtent.MinY) / (sGlobalExtent.MaxX - sGlobalExtent.MinX);

    int nWidth, nHeight;

    if (dfRatio < 1)
    {
        nWidth = 1024;
        nHeight = nWidth * dfRatio;
    }
    else
    {
        nHeight = 1024;
        nWidth = nHeight / dfRatio;
    }

    GDALDataset* poSrcDS = MEMDataset::Create( "MEM:::", nWidth, nHeight, 0, GDT_Byte, NULL );

    double adfGeoTransform[6];
    adfGeoTransform[0] = sGlobalExtent.MinX;
    adfGeoTransform[1] = (sGlobalExtent.MaxX - sGlobalExtent.MinX) / nWidth;
    adfGeoTransform[2] = 0;
    adfGeoTransform[3] = sGlobalExtent.MaxY;
    adfGeoTransform[4] = 0;
    adfGeoTransform[5] = - (sGlobalExtent.MaxY - sGlobalExtent.MinY) / nHeight;

    poSrcDS->SetGeoTransform(adfGeoTransform);

    OGRSpatialReference* poSRS = papoLayers[0]->GetSpatialRef();
    if (poSRS)
    {
        char* pszWKT = NULL;
        poSRS->exportToWkt(&pszWKT);
        poSrcDS->SetProjection(pszWKT);
        CPLFree(pszWKT);
    }

    oWriter.SetInfo(poSrcDS, papszOptions);

    oWriter.StartPage(poSrcDS,
                      dfDPI,
                      pszGEO_ENCODING,
                      pszNEATLINE,
                      &sMargins,
                      eStreamCompressMethod,
                      bWriteOGRAttributes);

    int iObj = 0;
    
    char** papszLayerNames = CSLTokenizeString2(pszOGRDisplayLayerNames,",",0);

    for(int i=0;i<nLayers;i++)
    {
        CPLString osLayerName;
        if (CSLCount(papszLayerNames) < nLayers)
            osLayerName = papoLayers[i]->GetName();
        else
            osLayerName = papszLayerNames[i];

        oWriter.WriteOGRLayer((OGRDataSourceH)this,
                              i,
                              pszOGRDisplayField,
                              pszOGRLinkField,
                              osLayerName,
                              bWriteOGRAttributes,
                              iObj);
    }

    CSLDestroy(papszLayerNames);

    oWriter.EndPage(pszExtraImages,
                    pszExtraStream,
                    pszExtraLayerName,
                    pszOffLayers,
                    pszExclusiveLayers);

    if (pszJavascript)
        oWriter.WriteJavascript(pszJavascript);
    else if (pszJavascriptFile)
        oWriter.WriteJavascriptFile(pszJavascriptFile);

    oWriter.Close();

    delete poSrcDS;

    return OGRERR_NONE;
}
Exemplo n.º 13
0
void wxGISMapView::AddLayer(wxGISLayer* pLayer)
{
	IDisplayTransformation* pDisplayTransformation = pGISScreenDisplay->GetDisplayTransformation();
	if(pDisplayTransformation->GetSpatialReference() == NULL)
	{
		OGRSpatialReference* pSpaRef = pLayer->GetSpatialReference();
		if(pSpaRef)
			pDisplayTransformation->SetSpatialReference(pSpaRef);
		else
		{
			OGREnvelope* pEnv = pLayer->GetEnvelope();
			if(pEnv)
			{
				if(pEnv->MaxX <= 180 && pEnv->MaxY <= 90 && pEnv->MinX >= -180 && pEnv->MinY >= -90)
				{
					OGRSpatialReference* pSpaRef = new OGRSpatialReference();
					pSpaRef->SetWellKnownGeogCS("WGS84");
					pDisplayTransformation->SetSpatialReference(pSpaRef);
				}
			}
		}
	}
	
	OGREnvelope* pEnv = pLayer->GetEnvelope();
	if(pEnv == NULL)
		return;
	OGRSpatialReference* pSpaRef = pLayer->GetSpatialReference();

	if(pSpaRef && pDisplayTransformation->GetSpatialReference())
	{
		if(!pDisplayTransformation->GetSpatialReference()->IsSame(pSpaRef))
		{
			OGRCoordinateTransformation *poCT = OGRCreateCoordinateTransformation( pSpaRef, pDisplayTransformation->GetSpatialReference() );
			poCT->Transform(1, &pEnv->MaxX, &pEnv->MaxY);
			poCT->Transform(1, &pEnv->MinX, &pEnv->MinY);
		}
	}

	if(!pDisplayTransformation->IsBoundsSet())
		pDisplayTransformation->SetBounds(*pEnv);
	else
	{
		OGREnvelope Bounds = pDisplayTransformation->GetBounds();
		Bounds.Merge(*pEnv);
		pDisplayTransformation->SetBounds(Bounds);
	}

	//caching
	if(pLayer->GetCached())
	{
		pLayer->SetCacheID(pGISScreenDisplay->AddCache());
	}
	else
	{
		if(m_Layers.size() > 0 && m_Layers[m_Layers.size() - 1]->GetCached())
			pLayer->SetCacheID(pGISScreenDisplay->AddCache());
		else
			pLayer->SetCacheID(pGISScreenDisplay->GetLastCacheID());
	}
	wxGISMap::AddLayer(pLayer);
}
Exemplo n.º 14
0
bool SubrasterByVector(wxGISFeatureDatasetSPtr pSrcFeatureDataSet, wxGISRasterDatasetSPtr pSrcRasterDataSet, CPLString &szDstFolderPath, wxGxRasterFilter* pFilter, GDALDataType eOutputType, int nBandCount, int *panBandList, bool bUseCounter, int nCounterBegin, int nFieldNo, double dfOutResX, double dfOutResY, bool bCopyNodata, bool bSkipSourceMetadata, char** papszOptions, ITrackCancel* pTrackCancel)
{
	//check if openned or/and open dataset
	if(!pSrcFeatureDataSet->IsOpened())
	{
		if(!pSrcFeatureDataSet->Open(true))
		{
			if(pTrackCancel)
				pTrackCancel->PutMessage(_("Source vector dataset open failed"), -1, enumGISMessageErr);
			return false;
		}
	}

	if(!pSrcRasterDataSet->IsOpened())
	{
		if(!pSrcRasterDataSet->Open(true))
		{
			if(pTrackCancel)
				pTrackCancel->PutMessage(_("Source raster dataset open failed"), -1, enumGISMessageErr);
			return false;
		}
	}

    const OGRSpatialReferenceSPtr pSrsSRS = pSrcFeatureDataSet->GetSpatialReference();
    const OGRSpatialReferenceSPtr pDstSRS = pSrcRasterDataSet->GetSpatialReference();
    OGRCoordinateTransformation *poCT(NULL);
    bool bSame = pSrsSRS == NULL || pDstSRS == NULL || pSrsSRS->IsSame(pDstSRS.get());
    if( !bSame )
	{
        poCT = OGRCreateCoordinateTransformation( pSrsSRS.get(), pDstSRS.get() );
		if(poCT == NULL)
		{
		    const char* err = CPLGetLastErrorMsg();
			wxString sWarn = wxString::Format(_("Create OGRCreateCoordinateTransformation failed! GDAL error: %s"), wxString(err, wxConvUTF8).c_str());
            wxLogWarning(sWarn);
			if(pTrackCancel)
				pTrackCancel->PutMessage(sWarn, -1, enumGISMessageWarning);
		}
	}

    IProgressor* pProgressor(NULL);
    if(pTrackCancel)
    {
       pProgressor = pTrackCancel->GetProgressor();
       pTrackCancel->PutMessage(wxString::Format(_("Start clip '%s' by geometry from '%s'"), wxString(pSrcRasterDataSet->GetPath(), wxConvUTF8).c_str(), wxString(pSrcFeatureDataSet->GetPath(), wxConvUTF8).c_str()), -1, enumGISMessageNorm);
    }
    int nCounter(0);
    if(pProgressor)
        pProgressor->SetRange(pSrcFeatureDataSet->GetFeatureCount());


/* -------------------------------------------------------------------- */
/*	Build band list to translate					                    */
/* -------------------------------------------------------------------- */
    if( nBandCount == 0 )
    {
        nBandCount = pSrcRasterDataSet->GetBandCount();
        if( nBandCount == 0 )
        {
		    if(pTrackCancel)
			    pTrackCancel->PutMessage(_("Input file has no bands, and so cannot be translated."), -1, enumGISMessageErr);
            return false;
        }

        panBandList = (int *) CPLMalloc(sizeof(int)*nBandCount);
        for(size_t i = 0; i < nBandCount; ++i )
            panBandList[i] = i + 1;
    }
    else
    {
        for(size_t i = 0; i < nBandCount; ++i )
        {
            if( panBandList[i] > pSrcRasterDataSet->GetBandCount() )
            {
		        if(pTrackCancel)
                    pTrackCancel->PutMessage(wxString::Format(_("Band %d requested, but only bands 1 to %d available."), panBandList[i], pSrcRasterDataSet->GetBandCount()), -1, enumGISMessageErr);
                return false;
            }
        }
    }

    bool bDefaultfilter(false);
    if(pFilter == NULL)
    {
        pFilter = new wxGxRasterFilter(enumRasterTiff);
        bDefaultfilter = true;
    }

    CPLString szDriver(pFilter->GetDriver().mb_str());
    CPLString szExt(pFilter->GetExt().mb_str());
    CPLString szBaseName = CPLGetBasename(pSrcRasterDataSet->GetPath());

	GDALDriver* pDriver = (GDALDriver*)GDALGetDriverByName( szDriver );
	if( pDriver == NULL )
    {
		if(pTrackCancel)
            pTrackCancel->PutMessage(wxString::Format(_("Output driver '%s' not recognised."), szDriver.c_str()), -1, enumGISMessageErr);
        if(bDefaultfilter)
            wxDELETE(pFilter);
		return false;
    }

    pSrcFeatureDataSet->Reset();
    OGRFeatureSPtr pFeature;
    size_t nNameCounter(nCounterBegin);
    while((pFeature = pSrcFeatureDataSet->Next()) != NULL)
    {
        if(pTrackCancel && !pTrackCancel->Continue())
        {
            wxString sErr(_("Interrupted by user"));
            CPLString sFullErr(sErr.mb_str());
            CPLError( CE_Warning, CPLE_AppDefined, sFullErr );

            if(pTrackCancel)
                pTrackCancel->PutMessage(wxString(sFullErr, wxConvLocal), -1, enumGISMessageErr);

            if(bDefaultfilter)
                wxDELETE(pFilter);
            return false;
        }

        OGRGeometry *pGeom = pFeature->GetGeometryRef();
		if(wkbFlatten(pSrcFeatureDataSet->GetGeometryType()) != wkbUnknown && !pGeom)
            continue;

		OGRGeometry *pNewGeom(NULL);
        if( !bSame && poCT )
        {
            if(pGeom)
            {
				pNewGeom = pGeom->clone();
                OGRErr eErr = pNewGeom->transform(poCT);
                if(eErr != OGRERR_NONE)
	                wxDELETE(pNewGeom);
            }
        }
		else
			pNewGeom = pGeom->clone();

		OGREnvelope GeomEnv;
		pNewGeom->getEnvelope(&GeomEnv);
		OGREnvelope RasterEnv = pSrcRasterDataSet->GetEnvelope();
		GeomEnv.Intersect(RasterEnv);
		if(GeomEnv.IsInit())
		{
            CPLString szPath;
			if(bUseCounter)
            {
                szPath.Printf("%s_%d", szBaseName.c_str(), nNameCounter++);
                CPLString sNewName(CheckUniqName(szDstFolderPath, szPath, szExt).mb_str(wxConvUTF8));
                szPath = CPLFormFilename(szDstFolderPath, sNewName, szExt);
            }
            else
            {
                CPLString szName = pFeature->GetFieldAsString(nFieldNo);
                CPLString sNewName(CheckUniqName(szDstFolderPath, szName, szExt).mb_str(wxConvUTF8));
                szPath = CPLFormFilename(szDstFolderPath, sNewName, szExt);
            }
			CreateSubRaster(pSrcRasterDataSet, GeomEnv, pNewGeom, pDriver, szPath, eOutputType, nBandCount, panBandList, dfOutResX, dfOutResY, bCopyNodata, bSkipSourceMetadata, papszOptions, pTrackCancel);
		}
        nCounter++;
        if(pProgressor)
            pProgressor->SetValue(nCounter);
    }

    if(poCT)
        OCTDestroyCoordinateTransformation(poCT);

    if(bDefaultfilter)
        wxDELETE(pFilter);

	return true;
}