8 Using the OpenCRG tools
8.1 Usage of the C-API
The C-API comprises methods for the following tasks:
-
Reading OpenCRG files.
-
Setting modifiers and options.
-
Evaluating OpenCRG data.
The C-API is especially suitable for applications for which fast evaluation is important. Typical use cases include driving simulators or test rigs.
A data set is the instance of data read from an OpenCRG file into memory. A data set is identified by a unique integer ID. This ID is returned by the data loader method. A data set stores the actual road data as well as modifiers and options defined in the file.
After the file has been read, the modifiers of the data set may be replaced, deleted or extended via API calls referring to that data set. Once the modifiers are defined, they must be applied via an API call.
A contact point provides access to a data set. In simulations, contact points can be used to model the touching point between a tire and the road surface. A contact point inherits all options from the corresponding data set. The options of a contact point may be replaced, deleted or extended via API calls referring to that contact point. In contrast to modifiers, options are applied implicitly whenever an evaluation is performed.
8.2 Usage of the MATLAB tools
The MATLAB tools contain scripts for the following tasks:
-
Reading OpenCRG files.
-
Setting modifiers and options.
-
Evaluating OpenCRG data.
-
Manipulating OpenCRG data.
-
Generating OpenCRG data.
-
Visualizing and analyzing OpenCRG data.
-
Mapping OpenCRG data to geographical positions.
-
Writing OpenCRG file.
The MATLAB tools are especially suitable for applications that require extended functionalities for processing, analysis and visualization. Typical use cases include generating OpenCRG files either synthetically or from measurement data and numerical simulations of driving dynamics.
When an OpenCRG file is loaded, all data associated with that file is stored in a single structure array. This structure array has the following fields:
head-
Structure array containing data corresponding to the road parameters section and the data definition section.
mods-
Structure array containing modifiers read from file or set via function calls.
opts-
Structure array containing options read from file or set via function calls.
ct-
Cell array containing header information text. Mandatory when writing to file, otherwise optional.
struct-
Optional cell array of further structured data, used for file output.
filenm-
File name of the associated OpenCRG file.
z-
Array of z-values.
u-
Definition of u-values.
v-
Definition of v-values.
b-
Vector of banking values (optional).
p-
Vector of heading angles (optional).
s-
Vector of slope values (optional).
mpro-
Map projection data.
fopt-
Figure options.
A minimal OpenCRG data set must at least define u, v and z.
For more detailed information on individual fields and subfields, run crg_intro from the MATLAB Command Window.
8.3 Reading OpenCRG files
Reading an OpenCRG file loads its content into memory.
8.3.1 Related C functions
int crgLoaderReadFile( const char* file )-
Read the OpenCRG file
fileand returns an integer data set ID. int crgDataSetRelease( int dataSetId )-
Destroy the OpenCRG data set
dataSetId.
8.3.2 Related MATLAB functions
[data] = crg_read(file)-
Read the OpenCRG file
fileand returns a structure arraydatacontaining the OpenCRG data.
8.4 Setting and applying modifiers
Modifiers provide a way to alter OpenCRG data without changing the actual data in the file.
With the C-API, you use function calls to set modifiers. For all modifiers and values, symbolic constants are defined in opencrg/c-api/baselib/inc/crgBaseLib.h. These constants should be used instead of their integer equivalents to improve readability of the code.
With MATLAB, you set modifiers by directly accessing the mods field of a data set using dot notation.
|
Modifiers, whether defined in an OpenCRG file or via function calls, are not applied automatically. They must be applied explicitly with a separate function call. |
8.4.2 Corresponding C functions
int crgDataSetModifierSetInt( int dataSetId, unsigned int modId, int modValue )-
Set the integer modifier
modIdof the data setdataSetIdto the valuemodValue. int crgDataSetModifierSetDouble( int dataSetId, unsigned int modId, double modValue )-
Set the double modifier
modIdof the data setdataSetIdto the valuemodValue. int crgDataSetModifierGetInt( int dataSetId, unsigned int modId, int* modValue )-
Get the current value of the integer modifier
modIDof the data setdataSetIdand store it inmodValue. extern void crgDataSetModifiersPrint( int dataSetId )-
Print the current modifier settings of the data set
dataSetId. int crgDataSetModifierGetDouble( int dataSetId, unsigned int modId, double* modValue )-
Get the current value of the double modifier
modIDof the data setdataSetIdand store it inmodValue. int crgDataSetModifierRemove( int dataSetId, unsigned int modId )-
Remove the modifier
modIDfrom the data setdataSetId. int crgDataSetModifierRemoveAll( int dataSetId )-
Remove all modifiers from the data set
dataSetId. void crgDataSetModifierSetDefault( int dataSetId )-
Set all modifiers of the data set
dataSetIdto their default values. void crgDataSetModifiersApply( int dataSetId )-
Apply set modifiers to the data set
dataSetId. If no modifiers are defined, the default modifier values are applied.
8.4.3 Corresponding MATLAB functions
[data] = crg_mods(data)-
Apply modifiers in
data.modsto the OpenCRG data indata. Afterwards, remove all modifiers fromdata.mods. Ifdata.modsdoes not exist, default modifier values are applied. Ifdata.modsis empty, no modifiers are applied.
8.4.4 Examples
8.4.4.1 C examples
The following example shows how to set and apply modifiers using the C-API.
/* load CRG file */ int dataSetId = crgLoaderReadFile( 'demo.crg' ); /* remove modifiers defined in file */ crgDataSetModifierRemoveAll( dataSetId ); /* set NaN-handling modifier using symbolic constants */ crgDataSetModifierSetInt( dataSetId, dCrgModGridNaNMode, dCrgGridNaNKeepLast ); /* set offset-position modifiers using both symbolic constants and numerical values */ crgDataSetModifierSetDouble( dataSetId, dCrgModRefLineOffsetX, 100.0 ); crgDataSetModifierSetDouble( dataSetId, dCrgModRefLineOffsetY, 200.0 ); crgDataSetModifierSetDouble( dataSetId, dCrgModRefLineOffsetZ, 10.0 ); /* apply modifiers to data set */ crgDataSetModifiersApply( dataSetId );
8.4.4.2 MATLAB examples
The following example shows how to set and apply modifiers using the MATLAB tools.
% load CRG file
data = crg_read('demo.crg');
% create mods struct
data.mods = struct;
/* set NaN-handling modifier */
data.mods.gnan = 2;
/* set offset-position modifiers */
data.mods.rlox = 100;
data.mods.rloy = 200;
data.mods.rloz = 10;
/* apply modifiers to data set */
data = crg_mods(data);
8.5 Creating and deleting contact points
In order to evaluate data with the C-API, you must create one or more contact points. Contact points provide access to a given data set. A contact point is identified by a unique integer ID. This ID is returned by the contact-point creation method. The number of contact points per data set is not limited.
In simulations, contact points can be used to model the touching point between a tire and the road surface.
|
When creating multithreaded applications to parallelize evaluation calls, create a separate contact point for each thread. Sharing contact points across different threads destroys data associated with that contact point. |
8.5.2 Corresponding C functions
int cpId = crgContactPointCreate( int dataSetId )-
Create a contact point with the ID
cpIdfor the data setdataSetId. int crgContactPointDelete( int cpId )-
Delete the contact point with the ID
cpId. int crgContactPointDeleteAll( int dataSetId )-
Delete all contact points associated with the data set
dataSetId.
8.5.4 Examples
8.5.4.1 C examples
The following example shows how to create two contact points with the C-API.
double z; /* load CRG file */ int dataSetId = crgLoaderReadFile( 'demo.crg' ); /* create two contact points */ int cpId1 = crgContactPointCreate( dataSetId ); int cpId2 = crgContactPointCreate( dataSetId );
8.6 Setting options
With the C-API, you set options via function calls. For all options and values, symbolic constants are defined in opencrg/c-api/baselib/inc/crgBaseLib.h. You should use the symbolic constants rather than their integer equivalents to make your code easier to read.
When you use the MATLAB tools to evaluate data, options stored with OpenCRG data are automatically taken into account. With MATLAB, you set options by directly accessing the opts field of a data set using dot notation.
|
Options, whether defined in an OpenCRG file or via function calls, are applied automatically when executing an evaluation call. |
8.6.1 Prerequisites
-
You have loaded an OpenCRG data set.
-
You have set and applied modifiers.
-
You have created a contact point (C only).
8.6.2 Corresponding C functions
int crgContactPointOptionSetInt( int cpId, unsigned int optionId, int optionValue )-
Set the integer option
optionIdof the contact pointcpIdto the valueoptionValue. int crgContactPointOptionSetDouble( int cpId, unsigned int optionId, double optionValue )-
Set the double option
optionIdof the contact pointcpIdto the valueoptionValue. int crgContactPointOptionGetInt( int cpId, unsigned int optionId, int* optionValue )-
Get the current value of the integer option
optionIdof the contact pointcpIdand store it inoption value. int crgContactPointOptionGetDouble( int cpId, unsigned int optionId, double* optionValue )-
Get the current value of the double option
optionIdof the contact pointcpIdand store it inoption value. void crgContactPointOptionsPrint( int cpId )-
Print the current option settings of the contact point
cpId. int crgContactPointOptionRemove( int cpId, unsigned int optionId )-
Remove the option
optionIDfrom the contact pointcpId. int crgContactPointOptionRemoveAll( int cpId )-
Remove all options from the contact point
cpId. void crgContactPointSetDefaultOptions( int cpId )-
Set all options of the contact point
cpIdto their default values.
8.6.3 Corresponding MATLAB functions
Options are set by directly accessing the opts field of a data set using dot notation.
8.6.4 Examples
8.6.4.1 C examples
The following example shows how to set options using the C-API.
/* load CRG file */ int dataSetId = crgLoaderReadFile( 'demo.crg' ); /* create contact point */ int cpId = crgContactPointCreate( dataSetId ); /* set border mode options to "Return NaN" */ crgContactPointOptionSetInt( cpId, dCrgCpOptionBorderModeU, dCrgBorderModeNone ); crgContactPointOptionSetInt( cpId, dCrgCpOptionBorderModeV, dCrgBorderModeNone ); /* evaluate z at (u,v) = [100 0] */ crgEvaluv2z( cpId, 100, 0, &z );
8.7 Evaluating OpenCRG data
Evaluation routines provide access to road data. Additionally, you can use the evaluation routines to transform data between different coordinate systems.
8.7.1 Prerequisites
-
You have loaded an OpenCRG data set.
-
You have set and applied modifiers.
-
You have created a contact point (C only).
-
You have set options.
8.7.2 Corresponding C functions
void crgEvaluv2z( int cpId, double u, double v, double* z )-
Evaluate the
z-value at a givenu/v-position for contact pointcpId. void crgEvalxy2z( int cpId, double u, double v, double* z )-
Evaluate the
z-value at a givenx/y-position for contact pointcpId. void crgEvaluv2xy( int cpId, double u, double v, double* x, double* y )-
Evaluate the
x/y-position of a givenu/v-position for contact pointcpId. void crgEvalxy2uv( int cpId, double x, double y, double* u, double* v )-
Evaluate the
u/v-position of a givenx/y-position for contact pointcpId. void crgEvaluv2pk( int cpId, double u, double v, double* phi, double* crv )-
Evaluate the heading angle
phiand the curvaturecrvat a givenu/v-position for contact pointcpId. int crgEvalxy2pk( int cpId, double x, double y, double* phi, double* curv )-
Evaluate the heading angle
phiand the curvaturecrvat a givenx/y-position for contact pointcpId.
8.7.3 Corresponding MATLAB functions
[pz, data] = crg_eval_uv2z(data, puv)-
Evaluate the
z-values at the givenu/v-positions for data setdata. [pz, data] = crg_eval_xy2z(data, pxy)-
Evaluate the
z-values at the givenx/y-positions for data setdata. [pxy, data] = crg_eval_uv2xy(data, puv)-
Evaluate the
x/y-positions of the givenu/v-positions for data setdata. [puv, data] = crg_eval_xy2uv(data, pxy)-
Evaluate the
u/v-positions of the givenx/y-positions for data setdata. [iu, iv] = crg_eval_uv2iuiv(data, u, v)-
Evaluate the index positions
iu,ivof the givenu/v-positions for data setdata. [phi, data] = crg_eval_u2phi(data, pu)-
Evaluate the heading angles
phiat givenu-positions for data setdata. [crv, data] = crg_eval_u2crv(data, pu)-
Evaluate the curvature values
crvat givenu-positions for data setdata. [pxyz, data] = crg_eval_enh2xyz(data, penh)-
Evaluate the local
x/y/'z'-positions of the given global positionspenh(easting, northing, height) for data setdata. [pxyz, data] = crg_eval_llh2xyz(data, pllh)-
Evaluate the local
x/y/'z'-positions of the given geographic coordinatespllh(latitude, longitude, height) for data setdata.datamust have appropriate map projection data. [penh, data] = crg_eval_xyz2enh(data, pxyz)-
Evaluate the global map positions
penh(easting, northing, height) of the given localx/y/'z'-positions-positions for data setdata. [pllh, data] = crg_eval_xyz2llh(data, pxyz)-
Evaluate the geographic coordinates
pllh(latitude, longitude, height) of the given localx/y/'z'-positions for data setdata.datamust have appropriate map projection data.
8.7.4 Examples
8.7.4.1 C examples
The following example shows how to evaluate z-values using the C-API.
double z; /* load CRG file */ int dataSetId = crgLoaderReadFile( 'demo.crg' ); /* create contact point */ int cpId = crgContactPointCreate( dataSetId ); /* evaluate z at (u,v) = [100 0] */ crgEvaluv2z( cpId, 100, 0, &z );
8.8 Manipulating OpenCRG data
OpenCRG data is usually changed by applying modifiers or setting options. However, there are some changes that you cannot achieve with modifiers or options. An example is when you need to prepare real-world data for use in simulations.
The MATLAB tools cover the following use cases:
-
Appending or cutting OpenCRG data sets.
-
Extracting and changing slope and banking.
-
Filtering and limiting z-values.
-
Flipping road data or mapping it to different coordinate systems.
8.8.3 Corresponding MATLAB functions
[data, roff2] = crg_append(data1, data2)-
Append an OpenCRG data set
data2to the OpenCRG data setdata1and return the resulting data setdata. For a smooth connection, the second grid is re-positioned so that both grids overlap for one longitudinal increment. The re-positioned data set is returned asroff2. The last latitudinal cut ofdataand the first latitudinal cut ofdata2are dropped. Incomplete or inconsistent WGS 84 values at the intersection result in omitting the WGS 84 information in the result. [data] = crg_cut_iuiv(data, iu, iv)-
Cut out a part of a OpenCRG road
data.iuandivspecify the index positions of the area to be cut out. [data] = crg_separate_sb(data, swlen, bwlen)-
Find and filter slope and banking in road data of
data. Slope and banking are filtered using a moving average with window lengthswlenandbwlen, respectively. Separate the filtered result from the road data leaving the total elevation information unchanged. [data] = crg_b2z(data, b)-
Apply new banking
bto the OpenCRG data indata. Merge existing banking into the road data. [data] = crg_s2z(data, rz)-
Apply new slope defined by
rzto the OpenCRG data indata. Merge existing slope into the road data. [data] = crg_ext_slope(data, p)-
Extract the slope from OpenCRG data in
data.ppis a smoothing parameter. [data] = crg_ext_banking(data, pp)-
Extract the banking from OpenCRG data in
data.ppis a smoothing parameter. [data] = crg_filter(data, iu, iv, fm, mask, wopt)-
Filter OpenCRG data in
data.iuandivcan be used to limit filtering to an area of the grid.fmspecifies the filtering method.maskspecifies the size of the filter mask. The optionalwoptdefines filter weights and number of repeated filter applications. [data] = crg_limiter(data, mmlim, iu, iv)-
Limit z-values in
datato the minimum and maximum defined inmmlim.iuandivcan be used to limit the operation to an area of the grid. [data] = crg_wrap(data)-
Wrap heading angles of road parameters and road data in
datato a +/- pi range. [data] = crg_flip(data)-
Flip the OpenCRG data in
data, swapping start and end while leaving the modifiers and options unchanged. [data] = crg_map_uv2uv(data, crg_uv, iu, iv)-
Map z-values of
crg_uvin u/v-coordinates to the u/v-grid ofdata.iuandivcan be used to limit the operation to an area of the grid. [data] = crg_map_xy2xy(data, crg_xy, iu, iv)-
Map z-values of
crg_xyin x/y-coordinates to the inertial x/y-coordinate system ofdata.iuandivcan be used to limit the operation to an area of the grid. [data] = crg_rerender(crg, inc, v)-
Re-render OpenCRG data in
crgasdatawith new u/v-incrementincand v-spacingv.
8.8.4 Examples
8.8.4.1 MATLAB examples
The following example shows how to manipulate data using the MATLAB tools.
% load OpenCRG data
data = crg_read('demo.crg');
% extract banking with smoothing
exdata = crg_ext_banking(data, 0.0000000000003);
% extract slope
exdata = crg_ext_slope(exdata);
% visualize results
crg_show_refline_elevation(exdata);
crg_show_elgrid_surface(exdata)
crg_show_road_surface(exdata);
8.9 Generating OpenCRG data
With the MATLAB tools, you can generate synthetic OpenCRG data. You can define section-wise curvature, banking and slope independently by using polynomials of grade 2.
8.9.3 Corresponding MATLAB functions
[data] = crg_gen_csb2crg0(inc, u, v, c, s, b)-
Generate a synthetic OpenCRG struct
datawith a regular grid, curvature, slope, and banking.incspecifies the increments in both u-direction and v-direction.uandvspecify the extend of the reference line.cspecifies the curvature.sspecifies the slope. [data, err] = crg_gen_ppxy2phi(ppxy, uinc, opts)-
Generate a partial OpenCRG struct
datawith reference line heading information by evaluating the given smooth polynomialppxyin pp-form.uincspecifies the reference line increment. The optional structoptsspecifies the discretization method, although the default method should be used in all cases.errcontains the position error after forward integration. [ppxy] = crg_gen_pxy2ppxy(pxy, opts)-
Generate a smooth polynomial
ppxyin pp-form from the given reference pointspxy. The optionaloptsstruct holds parameters for internal spline fit and spline smoothing functions. [v] = crg_check_uv_descript(uv_descript, posmode)-
Check whether the uv-description
uv_descriptis in a valid form and generate the associated v-profilev.
8.9.4 Examples
8.9.4.1 MATLAB examples
% minimal grid setup u = [ 0 900 ]; v = [ -2.50 2.5 ]; inc = [ 0.04 0.02]; % generate synthetical straight OpenCRG data data = crg_gen_csb2crg0(inc, u, v); % add z-values [nu nv] = size(data.z); z = 0.01*peaks(nv); z = repmat(z, ceil(nu/nv), 1); data.z(1:nu,:) = single(z(1:nu,:));
For more elaborate examples, see the MATLAB demo files.
8.10 Visualizing OpenCRG data
The C-API does not provide functions for visualizing OpenCRG data. However, the C-API provides some methods for displaying information about an OpenCRG data set.
The MATLAB tools provide a large collection of functions for visualizing OpenCRG data. crg_show() creates several figures visualizing different aspects of an OpenCRG data set. You can create each of these figures individually by calling the respective crg_show_*() function. These figures use subplots themselves. You can create each of these plots individually by calling the respective crg_plot_*() function.
8.10.1 Prerequisites
-
You have loaded an OpenCRG data set.
-
You have set and applied modifiers.
-
You have set options.
8.10.2 Corresponding C functions
void crgDataPrintHeader( int dataSetId )-
Print the header information of
dataSetId. void crgDataPrintChannelInfo( int dataSetId )-
Print information about the channels in
dataSetId. void crgDataPrintRoadInfo( int dataSetId );-
Print information about the road in
dataSetId.
8.10.3 Corresponding MATLAB functions
[data] = crg_show(data, iu, iv)-
Create several figures visualizing different aspects of OpenCRG data in
data.iuandivcan be used to limit the plots to a part of the grid. [data] = crg_show_refline_map(data, iu)-
Visualize the reference line defined in
datain a figure with several subplots.iucan be used to limit the plots to a range on the reference line. [data] = crg_show_refpnts_and_refline(data, pxy)-
Visualize the reference points in
pxyin relation to the reference line indata. [data] = crg_show_refline_elevation(data, iu)-
Visualize the z-values in
dataalong the reference line defined indatain a figure with several subplots.iucan be used to limit the plots to a range on the reference line. [data] = crg_show_elgrid_cuts_and_limits(data, iu, iv)-
Visualize the z-values in
dataas longitudinal and latitudinal cuts as well as the outer limits of the grid.iuandivcan be used to limit the plots to a part of the grid. [data] = crg_show_road_surface(data, iu, iv)-
Visualize the z-values in
datavia orthographic images and three-dimensional surface plots.iuandivcan be used to limit the plots to a part of the grid. [data] = crg_show_road_surface(data, iu, iv)-
Visualize the road surface described in
datavia orthographic images and three-dimensional surface plots.iuandivcan be used to limit the plots to a part of the grid. [data] = crg_show_road_uv2surface(data, u, v)-
Visualize the road surface described in
datavia orthographic images and three-dimensional surface plots on a grid given by the vectorsuandv. [data] = crg_show_info(data)-
Display information about
datain a text box. [ ] = crg_show_isequal(dd, out)-
Visualize
dd, the result of comparing two OpenCRG files.ddis usually the return value ofcrg_isequal().outcan be set tohtmlto publish the result as HTML. [data] = crg_show_peaks(data, pindex, su, sv, iu, iv)-
Visualize peaks at
pindexindata.pindexis usually the return value ofcrg_peakfinder().suandsvcan be used to limit the visualization of peaks to a part of the grid.iuandivcan be used to limit the plots to a part of the grid. [data] = crg_plot_refline_xy_overview_map(data, iu)-
Plot the reference line using x/y-coordinates.
iucan be used to limit the plots to a range on the reference line. [data] = crg_plot_refline_curvature(data, iu)-
Plot curvature along the reference line in
data.iucan be used to limit the plots to a range on the reference line. [data] = crg_plot_refline_elevation(data, iu)-
Plot z-values along the reference line in
data.iucan be used to limit the plots to a range on the reference line. [data] = crg_plot_refline_heading(data, iu)-
Plot the heading angle along the reference line of
data.iucan be used to limit the plots to a range on the reference line. [data] = crg_plot_refline_slope_bank(data, iu)-
Plot slope and banking along the reference line of
data.iucan be used to limit the plots to a range on the reference line. [data] = crg_plot_refline_xyz_map(data, iu)-
Plot the reference line using x/y/z-coordinates.
iucan be used to limit the plots to a range on the reference line. [data] = crg_plot_refline_xy_map_and_curv(data, iu)-
Plot the reference line using x/y-coordinates as well as its curvature.
iucan be used to limit the plots to a range on the reference line. [data] = crg_plot_elgrid_limits(data, iu, iv)-
Plot the outer limits of the data in
datain the current axis object.iuandivcan be used to limit the plots to a part of the grid. [data] = crg_plot_elgrid_cross_sect(data, iu, iv)-
Plot z-values of
dataover v for various u-coordinates.iuandivcan be used to limit the plots to a part of the grid. [data] = crg_plot_elgrid_long_sect(data, iu, iv)-
Plot z-values of
dataover u for various v-coordinates.iuandivcan be used to limit the plots to a part of the grid. [data] = crg_plot_elgrid_uvz_map(data, iu, iv)-
Plot z-values in
dataas orthographic image over an uncurved grid using u/v-coordinates.iuandivcan be used to limit the plots to a part of the grid. [data] = crg_plot_elgrid_xyz_map(data, iu, iv)-
Plot z-values in
dataas three-dimensional image over a curved grid using x/y-coordinates.iuandivcan be used to limit the plots to a part of the grid. [data] = crg_plot_refpnt_distances(data, pxy)-
Plot the distance of a series of reference points
pxyto the reference line described indata. The reference points use x/y-coordinates. [data] = crg_plot_road_uvz_map(data, iu, iv)-
Plot the road surface in
dataas orthographic image over an uncurved grid.iuandivcan be used to limit the plots to a part of the grid. [data] = crg_plot_road_xyz_map(data, iu, iv)-
Plot the road surface in
dataas three-dimensional image over a curved grid.iuandivcan be used to limit the plots to a part of the grid. [data] = crg_plot_road_uv2uvz_map(data, u, v)-
Plot the road surface in
dataas orthographic image over an uncurved grid given by the vectorsuandv. [data] = crg_plot_road_uv2xyz_map(data, u, v)-
Plot the road surface in
dataas three-dimensional image over a curved grid given by the vectorsuandv. [data] = crg_surf(data, x, y, z)-
Create a three-dimensional surface plot of
zoverxandyusing figure options defined indata. [data] = crg_figure(data)-
Set up an OpenCRG figure using the figure options in
data.fopt. [ ] = copy_ax2fig()-
Copy the current axis object to a new figure. This function is most useful if called by a mouse-click action in a subplot of a complex figure.
8.11 Mapping OpenCRG data to geographical positions
The C-API does not provide functions for handling geographical coordinates. Instead, the C-API ignores any data associated with map projections.
The MATLAB tools provide a large collection of functions for visualizing, converting and transforming geographic data. Figure 5 shows the available coordinate systems and transformations. Many of these functions are generic and may also be used for data not in OpenCRG format.
Map projection data can be defined either in the OpenCRG file or by accessing the relevant fields of the loaded OpenCRG data.
8.11.1 Prerequisites
-
You have loaded an OpenCRG data set.
-
The OpenCRG data contains the required map projection data.
8.11.3 Corresponding MATLAB functions
map_intro[]-
Display introductory information on handling geographic data.
[data] = crg_wgs84_crg2html(data, file, opts)-
Generate a HTML file
fileto display OpenCRG datadataas a track in a web-based map using OpenLayers.optscontains various options for changing the generated HTML file. [file] = map_wgs2html(llh, file, opts)-
Generate a HTML file
fileto display WGS 84 positionsllhas a track in a web-based map using OpenLayers.optscontains various options for changing the generated HTML file. [enh ell pro] = map_geod2pmap(llh, ell, pro)-
Convert points
llhfrom geodetic coordinates to map coordinates using a forward projection. An ellipsoid structelland a map projection structpromay be optionally provided. [enh ell pro] = map_geod2pmap_tm(llh, ell, pro)-
Convert points
llhfrom geodetic coordinates to map coordinates using forward transverse Mercator projection. An ellipsoid structelland a map projection structpromay be optionally provided. [llh ell pro] = map_pmap2geod_tm(enh, ell, pro)-
Convert points
enhfrom map coordinates to geodetic coordinatesllhusing backward transverse Mercator projection. An ellipsoid structelland a map projection structpromay be optionally provided. [xyz ell] = map_geod2ecef(llh, ell)-
Convert points
llhfrom a geodetic system to ECEF system. An ellipsoid structellmay be optionally provided. [xyzb tran] = map_ecef2ecef(xyza, tran, fwbw)-
Transforms points
xyzafrom one ECEF datum to another. A transformation structtranspecifying the transformation may be optionally provided. The optionalfwbwflag specifies, whether to use forward or backward transformation. [llh ell] = map_ecef2geod(xyz, ell)-
Convert points from a ECEF system to a geodetic system. An ellipsoid struct
ellmay be optionally provided. [enh dat] = map_global2plocal(llh, dat)-
Convert points from global geodetic coordinates
llhto local map coordinatesenhby transforming from global to local ellipsoid and forward projection on local ellipsoid.datcontains information necessary for the conversion. [llh dat] = map_plocal2global(enh, dat)-
Convert points from local map coordinates
enhto global geodetic coordinatesllhby backward projection on a local ellipsoid and datum transformation from a local to global ellipsoid.datcontains information necessary for the conversion. [phi ell pro] = map_ptm_north2initiallat(north, ell, pro)-
Compute the initial latitude values
phifor given northingsnorth. Utility function needed for transverse Mercator projections. [marc ell pro] = map_ptm_phi2marc(phi, ell, pro)-
Compute the meridional arc
marcfor given latitudesphi. Utility function needed for transverse Mercator projections. [dat] = map_check(dat)-
Check and update
datas used inmap_global2plocalandmap_plocal2global. [ell] = map_check_elli(ell)-
Check and update ellipsoid struct
ell. [pro] = map_check_proj(pro)-
Check and update map projection struct
pro. [tran] = map_check_tran(tran)-
Check and update datum transformation struct
tran. [url] = crg_wgs84_wgs2url(wgs, opts)-
Generate a URL
urlfor showing WGS 84 coordinateswgsusing Google Maps.opts.labelcontains a label for the positions. [wgs, data] = crg_wgs84_xy2wgs(data, pxy)-
Transform points
pxygiven in local x/y-coordinates to WGS 84 coordinateswgsusing the provided OpenCRG datadataas reference. [wgs] = crg_wgs84_wgsxy2wgs(wgs1, wgs2, pxy1, pxy2, pxy, eps, tol, dmin)-
Transforms points
pxygiven in local x/y-coordinates to WGS 84 coordinates. This transformation uses two reference points. These reference points are passed to the function using both WGS 84 coordinates (wgs1,wgs2) and local x/y-coordinates (pxy1,pxy2).eps,tolanddmindefine requirements for numerical consistency. [dist dbeg dend] = crg_wgs84_dist(wgs1, wgs2)-
Evaluate the distances
distand bearingsdbeganddendbetween the WGS 84 positions inwgs1andwgs2.dbegis the bearing as seen fromwgs1.dendis the bearing as seen fromwgs2. [wgs2 dend] = crg_wgs84_invdist(wgs1, dbeg, dist)-
Calculate WGS 84 positions
wgs2defined by a WGS 84 base positionwgs1, a bearingdbeg, and a distancedist.dendis the bearing as seen fromwgs2. [data] = crg_wgs84_setend(data, dref)-
Set missing WGS 84 end coordinate with given beginning-to-end direction for the reference line.
8.11.4 Examples
8.11.4.1 MATLAB examples
The following example shows the conversion of WGS 84 coordinates to UTM coordinates. As the example position is located Bavaria, Germany, the grid zone is 32U. Both UTM and WGS 84 use the same ellipsoid. Thus, a datum transformation is not required.
% example position ASAM e.V. % (Altlaufstraße 40, 85635 Höhenkirchen-Siegertsbrunn) org_llh = [ 48.02331, 11.71584, 584.0]; % WGS 84 % create mpro mpro.gell.nm='WGS84'; % global datum mpro.proj.nm='UTM_32U'; % map projection including local datum % WGS 84 llh degree -> WGS 84 llh radian llh = [pi/180*org_llh(1), pi/180*org_llh(2), org_llh(3)]; % transform WGS 84 llh radian -> UTM_32U enh_utm = map_geod2pmap_tm(llh, mpro.gell, mpro.proj)
The following example shows the conversion WGS 84 coordinates to GK3 coordinates. As the example position is located Bavaria, Germany, the zone number is 4. A datum transformation is required, because GK3 uses the BESSELDHDN ellipsoid, which is different from the WGS 84 ellipsoid.
% example position ASAM e.V. % (Altlaufstraße 40, 85635 Höhenkirchen-Siegertsbrunn) org_llh = [ 48.02331, 11.71584, 584.0]; % WGS 84 % create mpro mpro.gell.nm='WGS84'; mpro.lell.nm='BESSELDHDN'; mpro.proj.nm='GK3_4'; mpro.tran.nm='HN7'; % transformation % 7 Parameter Helmert transformation (example for Bavaria from LDBV) mpro.tran.ds = -5.2379 * 0.000001; mpro.tran.rx = (0.7201 / 3600) * (pi / 180); mpro.tran.ry = (0.1112 / 3600) * (pi / 180); mpro.tran.rz = (-1.7209 / 3600) * (pi / 180); mpro.tran.tx = -604.7365; mpro.tran.ty = -72.3946; mpro.tran.tz = -424.402; mpro=map_check(mpro); % WGS 84 llh degree -> WGS 84 llh radian llh = [pi/180*org_llh(1), pi/180*org_llh(2), org_llh(3)]; % transform WGS 84 llh radian -> GK3 zone 4 (BESSELDHDN) % transformation includes datum transformation, see map_global2plocal.m enh_gk = map_global2plocal(llh, mpro)
8.12 Checking OpenCRG data
OpenCRG data can contain inconsistent definitions, for example, definitions in the road parameters section that do not match the actual data in the road data section. Checking OpenCRG data ensures internal consistency, accuracy, and completeness.
Another example are intersecting lateral cuts caused by high curvature, resulting in an ambiguous grid definition. A global curvature check fails if two or more lateral cuts intersect inside the road limits. In this case, the local curvature check still succeeds, if such an intersection falls into a region of NaN values.
With the C-API, OpenCRG data is not checked automatically upon reading. It must be checked explicitly via an appropriate API call.
Most functions of the MATLAB tools already call crg_check internally. With the MATLAB tools, it is usually not required to check OpenCRG data explicitly.
8.12.2 Corresponding C functions
int crgCheck( int dataSetId )-
Check OpenCRG data
dataSetIdfor consistency and accuracy and returnstrueif the data was checked successfully. Check reference line curvature indataSetIdglobally and locally, if the respective options are set.
8.12.3 Corresponding MATLAB functions
[data] = crg_check(data)-
Run all available checks on the OpenCRG data in
data. [data] = crg_check_opts(data)-
Check OpenCRG options in
datafor consistent definitions and values. [data] = crg_check_mods(data)-
Check OpenCRG modifiers in
datafor consistent definitions and values. Provide missing defaults. [data] = crg_check_head(data)-
Check OpenCRG road parameters in
datafor consistent definitions and values. [data] = crg_check_mpro(data)-
Check OpenCRG map projection data in
datafor consistent definitions and values. [data] = crg_check_data(data)-
Check OpenCRG data in
datafor consistency and accuracy, fix minor accuracy problems, and complement and condense the OpenCRG data as far as possible. [data, ierr] = crg_check_curvature(data, ierr)-
Check reference line curvature in
dataglobally. Check reference line curvature indatalocally, if the respective option is set. [data] = crg_check_single(data)-
Check whether OpenCRG data in core data vectors and arrays of
datais of type single. [data] = crg_check_wgs84(data)-
Check whether the start position and the end position in
dataare consistently defined in both x/y/z-coordinates and WGS 84 coordinates.
8.12.4 Examples
8.13 Writing OpenCRG files
With the MATLAB tools, you can create OpenCRG files from OpenCRG data in memory. These files use KRBI or LRFI format. Therefore, road data must be converted to type single before writing it to file.
8.13.3 Related MATLAB functions
[ier] = crg_write(data, file, type)-
Write the OpenCRG data in
datato the OpenCRG filefile. By default, the file uses the KRBI format. The optional argumenttypemay be used to specify LRFI format instead. Therefore, road data must be converted to type single first.ierindicates whether any errors occurred while writing the file. [data] = crg_single(data)-
Convert road data in
datato type single.