Ejemplo n.º 1
0
Datum
spherepoint_in(PG_FUNCTION_ARGS)
{
	SPoint	   *sp = (SPoint *) palloc(sizeof(SPoint));
	char	   *c = PG_GETARG_CSTRING(0);
	double		lng,
				lat;

	void		sphere_yyparse(void);

	init_buffer(c);
	sphere_yyparse();
	if (get_point(&lng, &lat))
	{
		sp->lng = lng;
		sp->lat = lat;
		spoint_check(sp);
	}
	else
	{
		reset_buffer();
		pfree(sp);
		sp = NULL;
		elog(ERROR, "spherepoint_in: parse error");
	}
	reset_buffer();
	PG_RETURN_POINTER(sp);
}
Ejemplo n.º 2
0
  Datum  spheretrans_in(PG_FUNCTION_ARGS)
  {
    SEuler   * se   = ( SEuler * ) MALLOC ( sizeof ( SEuler ) ) ;
    char      *  c  = PG_GETARG_CSTRING(0);
    unsigned char etype[3];
    int            i;

    void sphere_yyparse( void );

    init_buffer ( c );
    sphere_yyparse();

    if ( get_euler ( &se->phi, &se->theta, &se->psi, etype ) ){

      for ( i=0; i<3; i++ ){
        switch ( i ){
          case 0:  se->phi_a   = etype[i] ; break;
          case 1:  se->theta_a = etype[i] ; break;
          case 2:  se->psi_a   = etype[i] ; break;
        }
      }
      spheretrans_check(se);
    } else {
      reset_buffer();
      FREE( se );
      se = NULL;
      elog ( ERROR , "spheretrans_in: parse error" );
    }
    reset_buffer();
    PG_RETURN_POINTER( se );
  }
Ejemplo n.º 3
0
  Datum  spherepoly_in(PG_FUNCTION_ARGS)
  {
    SPOLY * poly ;
    char  * c  = PG_GETARG_CSTRING(0);
    static int32  i, nelem;

    void sphere_yyparse( void );
    init_buffer ( c );
    sphere_yyparse() ;

    nelem = get_path_count( ) ;
    if ( nelem > 2 ){
      SPoint arr[nelem];
      for ( i = 0; i<nelem ; i++ ){
         get_path_elem ( i , &arr[i].lng , &arr[i].lat );
      }
      poly  = spherepoly_from_array ( &arr[0], nelem );
    } else {
      reset_buffer();
      elog ( ERROR , "spherepoly_in: more than two points needed" );
      PG_RETURN_NULL();
    }
    reset_buffer();

    PG_RETURN_POINTER( poly );
  }
Ejemplo n.º 4
0
  Datum  spherecircle_in(PG_FUNCTION_ARGS)
  {
    SCIRCLE  * c  = ( SCIRCLE * ) MALLOC ( sizeof ( SCIRCLE ) ) ;
    char     * s  = PG_GETARG_CSTRING(0);
    double lng, lat, radius ;

    void sphere_yyparse( void );

    init_buffer ( s );
    sphere_yyparse();
    if ( get_circle( &lng, &lat, &radius ) ){
      c->center.lng  = lng;
      c->center.lat  = lat;
      c->radius      = radius;
      reset_buffer();
      /*
        It's important to allow circles with radius 90deg!!      
      */
      if ( FPgt(c->radius,PIH) ){
        FREE( c );
        c = NULL;
        elog ( ERROR , "spherecircle_in: radius must be not greater than 90 degrees" );
      } else if ( FPeq(c->radius,PIH) ){
        // set "exact" 90 degrees
        c->radius = PIH;
      }
      spoint_check ( &c->center );
    } else {
      reset_buffer();
      FREE( c );
      c = NULL;
      elog ( ERROR , "spherecircle_in: parse error" );
    }
    PG_RETURN_POINTER( c );
  }