[OSRS-PROJ] CBuilder and Delphi

AYDIN ERTURK agerturk at meteor.gov.tr
Thu Jul 25 04:18:41 EDT 2002


Hi Alex,

I give you some detail my works.
I have been working remote sensing division in meteorology service as
a software engineer. We have one meteorological radar and satellite
ground receiving system (both NOAA and METOSAT).
A software is running to display radar data but it isn't efficient. So
I have written a program to display radar data by using CBuilder.
But I couldn't transfer longitude latitude to a plain coordinate
system. I have radar point longitude latitude and vertical and
horizontal resolution and projection system (mercator).
Furthermore I have C++ source code in UNIX that solve
this problem but I couldn't modify to Windows and CBuilder.
Code is below.

I have some other problems about cartography software.
If it is possible I can write you.

Regards

Aydin




// --- -*- C++ -*- ------------------------------------------------------

#include <iostream>
#include <stdio.h>
#include "project.h"

Project::Project (float centerLatitude, float centerLongitude,
    float xResolutionKM, float yResolutionKM)
{
    char** params = new char*[6];
    params[0] = new char[32];
    strcpy (params[0], "proj=merc"); // Use a Mercator projection
    params[1] = new char[32];
    strcpy (params[1], "ellps=WGS84"); // Use a standard ellipsoid model of
Earth
    params[2] = new char[32];
    strcpy (params[2], "units=km"); // Kilometer units
    params[3] = new char[32];
    sprintf (params[3], "lat_0=%3.5f", centerLatitude);
    params[4] = new char[32];
    sprintf (params[4], "lon_0=%3.5f", centerLongitude);
    params[5] = NULL;

    if (!(_pref = pj_init (5, params)))
    {
 cerr << "Projection init failed" << endl;
    }

    _xres = xResolutionKM;
    _yres = yResolutionKM;

    UV center;
    center.u = centerLongitude*DEG_TO_RAD;
    center.v = centerLatitude*DEG_TO_RAD;

    if (_pref)
    {
 center = pj_fwd (center, _pref);
 if (center.u == HUGE_VAL || center.v == HUGE_VAL)
 {
     cerr << "Projection failed" << endl;
 }
 else
 {
     _cx = center.u;
     _cy = center.v;
 }
    }

    // ... deallocate strings

    for (int i = 0; i < 5; i++)
    {
 delete[] params[i];
    }
    delete[] params;
}

Project::~Project ()
{
    if (_pref)
    {
 pj_free (_pref);
    }
}

bool Project::project (int xcoord, int ycoord, float& latitude, float&
longitude)
{
    if (!_pref)
    {
 latitude = longitude = 0;
 return false;
    }
    UV point;
    point.u = _cx+xcoord*_xres;
    point.v = _cy+ycoord*_yres;
    point = pj_inv (point, _pref);
    if (point.u == HUGE_VAL || point.v == HUGE_VAL)
    {
 cerr << "projection failed" << endl;
 latitude = longitude = 0;
 return false;
    }
    else
    {
 latitude = point.v*RAD_TO_DEG;
 longitude = point.u*RAD_TO_DEG;
    }
    return true;
}

bool Project::project (int xcoord, int ycoord, string& latitude, string&
longitude)
{
    float lon, lat;
    if (project (xcoord, ycoord, lat, lon))
    {
 // Create string representation of degrees
 degToString (lat, lon, latitude, longitude);
 return true;
    }
    return false;
}

void Project::degToString (float lat, float lon,
      string& latstr, string& lonstr)
{
    static char _latstr[32];
    static char _lonstr[32];

    char dir = (lat < 0.0 ? 'S' : 'N');
    lat = fabsf (lat);
    int deg = int (lat);
    int min = int ((((lat-float (deg))*3600)/60));
    int sec = int ((((lat-float (deg))*3600)-(min*60)));
    sprintf (_latstr, " %02d°%02d'%02d\"%c", deg, min, sec, dir);

    dir = (lon < 0.0 ? 'W' : 'E');
    lon = fabsl (lon);
    deg = int (lon);
    min = int ((((lon-(float)deg)*3600)/60));
    sec = int ((((lon-(float)deg)*3600) - (min*60)));

    sprintf (_lonstr, " %03d°%02d'%02d\"%c", deg, min, sec, dir);

    latstr = _latstr;
    lonstr = _lonstr;
}


#ifdef UNIT_TEST

#include <iostream>

using namespace std;

int main (int argc, char* argv[])
{
    float clat, clon;
    float xres, yres;
    cout << "Enter center latitude: " << flush;
    cin >> clat;
    cout << "Enter center longitude: " << flush;
    cin >> clon;
    cout << "Enter horizontal resolution in kilometers: " << flush;
    cin >> xres;
    cout << "Enter vertical resolution in kilometers: " << flush;
    cin >> yres;

    Project p (clat, clon, xres, yres);

    cout << "Coordinates are measured from center point. Center of
projection" << endl;
    cout << "is origin (0,0). Hit ^C to quit." << endl;
    for (;1;)
    {
 int x, y;
 string lat, lon;
 cout << "Enter coordinates (x y): " << flush;
 cin >> x >> y;

 if (p.project (x, y, lat, lon))
 {
     cout << "x=" << x << " -> longitude=" << lon << endl;
     cout << "y=" << y << " -> latitude=" << lat << endl;
 }
 else
 {
     cerr << "Couldn't project " << x << "," << y << endl;
 }
    }
}

#endif


And Header File.


// --- -*- C++ -*- ------------------------------------------------------
#ifndef _project_h_
#define _project_h_

#include <string>
extern "C" {
#include "projects.h"
};

using namespace std;

class Project
{
public:

    Project (float centerLatitude, float centerLongitude,
      float xResolutionKM, float yResolutionKM);

    virtual ~Project ();

    //
    // xcoord and ycoord is measured from center, i.e. center of image is
    // origin (0,0)
    //

    bool project (int xcoord, int ycoord, float& latitude, float&
longitude);
    bool project (int xcoord, int ycoord, string& latitude, string&
longitude);

    void degToString (float lat, float lon, string& latstr, string& lonstr);

protected:

private:

    PJ* _pref;
    float _xres, _yres;
    float _cx, _cy;
};

#endif // _project_h_

----- Original Message -----
From: "Alexander Weidauer" <alex.weidauer at huckfinn.de>
To: <osrs-proj at remotesensing.org>
Sent: Wednesday, July 24, 2002 3:03 PM
Subject: Re: [OSRS-PROJ] CBuilder and Delphi


AYDIN ERTURK wrote:

>Hi,
>Thank you for your answer.
>I downloaded prod.dll and projapi and i modified testproj (for Delphi)
>applivation.
>So it worked.
>But i could not understand the results.
>I want to do that I have radar data and center point langitude and latitude
>are known.
>How can convert pixel to geographic coordinate by using proj4 lib.
>
>Regards
>
>----- Original Message -----
>From: "Alexander Weidauer" <alex.weidauer at huckfinn.de>
>To: <osrs-proj at remotesensing.org>
>Sent: Tuesday, July 23, 2002 10:10 PM
>Subject: Re: [OSRS-PROJ] CBuilder and Delphi
>
>
>AYDIN ERTURK wrote:
>
>>Hello,
>>
>>
>>
>>I want to use proj4 lib with in CBuilder.
>>
>>Could you help me about this work?
>>
>>
>>
>>Aydin Gürol Ertürk
>>Software Engineer
>>Remote Sensing Division
>>Turkish State Meteorological Service
>>
>Hi all,
>
>I've uploaded the sources for the BCC5.5 proj 4 DLL and API Project.
>You can download binaries and sources under
>
>http://www.triplexware.huckfinn.de/geogfix.html#proj
>
>Sorry a better documentation is coming soon. ;o(~
>
>Frank, I' have copylefted my stuff under mozilla 1.1 it's ok ?
>
>Bye Alex
>
>
>
>
>----------------------------------------
>PROJ.4 Discussion List
>See http://www.remotesensing.org/proj for subscription, unsubscription
>and other information.
>
>
>----------------------------------------
>PROJ.4 Discussion List
>See http://www.remotesensing.org/proj for subscription, unsubscription
>and other information.
>
Hi Aydin,

I don't know how how your project is defined and how your transformation
jobflow works.
The porj library gives you the possibility to transfor coordinates
between  catrographic/geographic
and geodestic datums (like longitude latitude to a plain coordinate
system). If you have a "user
coordinate system" like a image or a local location measurement you have
to reference this system to
one of  in your background laying geographic coordinate systems (p.h.a
satellite image will be
referenced and resampled to a UTM map datum).  After this operation you
can determin the geodestic
coordinates.

If you use direct polar coordinates like in geophysical applications
(earthquake location, satellite positions or
positions of air planes) you can use Great Circla Calculations (..see
geod in the proj project or
function geodetic in uCoordinates).

To answer your questions more exactly I need more informations about
your problem.

Bye Alex



----------------------------------------
PROJ.4 Discussion List
See http://www.remotesensing.org/proj for subscription, unsubscription
and other information.

----------------------------------------
PROJ.4 Discussion List
See http://www.remotesensing.org/proj for subscription, unsubscription
and other information.



More information about the Proj mailing list