Home| general |src.lib|map| MapStereographic Index

MapStereographic

Syntax
int MapStereographic(int ssze,void *src,int dsze,void *dst,void *data);
Header
general/rmap.h
Library
map
Description

The MapStereographic performs a stereographic projection of a map coordinate.

The size in bytes of the input coordinate is given be the argument ssze. The coordinate data is pointed to by the argument src. The first two elements stored in the coordinate data block are assumed to be single precision floating point numbers of type float that represent the longitude and latitude of the coordinate.

The size in bytes of the output coordinate is given be the argument dsze. The coordinate data is pointed to by the argument dst. The first two elements stored in the coordinate data block are assumed to be single precision floating point numbers of type float that represent the cartesian coordinates calculated from the transform. The coordinates are normalized so that they range from zero to (1).

The argument data is a pointer to an array of single precision floating point numbers that contains the parameters of the transform. The first two elements of the array define the latitude and longitude of the center of the projection. The third element is a scaling factor for the projection. The final element is a flag indicating whether the projection should be mirrored about the y-axis.

Returns
Returns zero if the transformation was successful.On error, (-1) is returned.
Errors
On error, (-1) is returned.
Example



Source Code: MapStereographic.c

/* MapStereographic.c
   ==================
   Author: R.J.Barnes
 Copyright (c) 2012 The Johns Hopkins University/Applied Physics Laboratory

This file is part of the Radar Software Toolkit (RST).

RST is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.

Modifications:




#include <stdio.h>
#include <stdlib.h>
#include "rtypes.h"
#include "rxml.h"
#include "option.h"
#include "rfbuffer.h"
#include "rplot.h"
#include "polygon.h"
#include "rmap.h"

struct PolygonData *map;
struct PolygonData *nmap;
struct PolygonData *pmap;

struct PolygonData *clip;

int stream(char *buf,int sze,void *data) {
  FILE *fp;
  fp=(FILE *) data;
  fwrite(buf,sze,1,stdout);
  return 0;
} 

int main(int argc,char *argv[]) {

  struct Rplot *rplot=NULL;

  float wdt=400,hgt=400;


 float src[2],dst[2];

  unsigned int bgcol=0xffffffff;
  unsigned int lndcol=0xffa0ffa0;
  unsigned int seacol=0xffa0a0ff;
  unsigned int grdcol=0xffa00000;

 
  MapTransform  tfunc;
  float marg[3];

  int s;  
  char *envstr;
  FILE *mapfp;

  envstr=getenv("MAPDATA");

  mapfp=fopen(envstr,"r");
  map=MapFread(mapfp);
  fclose(mapfp);   

  marg[0]=90.0;
  marg[1]=0.0;
  marg[2]=1.0;

  tfunc=MapStereographic;

  clip=MapCircleClip(10); 

  nmap=PolygonTransform(map,2*sizeof(float),PolygonXYbbox,
                        tfunc,marg);

  pmap=PolygonClip(clip,nmap); 
 
  rplot=RplotMake();
  RplotSetText(rplot,stream,stdout);   
  RplotMakeDocument(rplot,"MapStereographic","1",wdt,hgt,24);

  RplotMakePlot(rplot,"MapCircleRead",wdt,hgt,24);

  RplotRectangle(rplot,NULL,0,0,wdt,hgt,
                  1,bgcol,0x0f,0,NULL);
  RplotEllipse(rplot,NULL,wdt/2,hgt/2,wdt/2,hgt/2,
                  1,seacol,0x0f,0,NULL);

  MapPlotPolygon(rplot,NULL,0,0,wdt,hgt,1,lndcol,0x0f,0,NULL,
                   pmap,1);

  MapPlotPolygon(rplot,NULL,0,0,wdt,hgt,1,lndcol,0x0f,0,NULL,
                   pmap,3);
  
  MapPlotPolygon(rplot,NULL,0,0,wdt,hgt,1,seacol,0x0f,0,NULL,
                   pmap,0);

  src[0]=53.2;
  src[1]=160.0;

  s=MapStereographic(2*sizeof(float),src,
                                  2*sizeof(float),dst,marg);

  if (s==0) 
    RplotEllipse(rplot,NULL,wdt*dst[0],hgt*dst[1],8,8,
                  1,grdcol,0x0f,0,NULL);



  RplotEndPlot(rplot);
  RplotEndDocument(rplot);
  return 0;
}