Learning nine advanced elements of building applications with FME objects

Source: Internet
Author: User
Tags types of functions

In this tutorial, the third section describes the attributes, geometric figures, and coordinate systems of the FME Element Object fmeofeature. Chapter 3 is the basis of this chapter. This chapter describes more and more powerful element processing functions.

 

When introducing element processing, it is necessary to distinguish between element-based processing and set-based processing. element-based processing refers to the independent elements of operations, and set-based processing refers to a batch of independent elements of operations.

 

This chapter will learn:

    • Create a topology (based on a set)
    • Converged polygon (based on set)
    • Buffer elements (based on elements)
    • Generate interior points of a polygon (based on elements)
    • Execute any function on elements (based on elements)
    • Geometric elements of offset, rotation, and scaling (based on elements)
    • Operational aggregation elements (based on elements and sets)
    • Operating Environment Elements (based on elements and sets)
    • Factory pipeline (based on elements and sets)

 

Create a topology

Some GIS geometric elements are used to reflect a spaghetti (Highway) data model. In highway models, any geometric elements depend on other elements in the set.

 

Generally, spatial data processing is converted from a highway model to a topological model to a plane element. If the line has an appropriate node FME, this problem can be solved: when you create a topology for the start and end locations (or nodes) of a wired intersection node, it is a typical collection-Based Element Processing.

 

There are 10 Line Element A below, which is a highway model. The topology model results in aggregation Element B. Note that F10 is not included in the topology because it does not form a surface element.

The processfeatures method of fmeofeature provides a simple method to create a topological plane for lines with correct nodes, this method creates a surface element from a polygon, a ring, and a polygon and a ring.

For example, m_fmefeaturevector contains a set of line elements with the same feature type and element attributes.CodeUse processfeatures to create a surface from m_fmefeaturevector. All the surface element attributes are cloned from the first line element:

set fmeparams = m_fmesession.createstringarray
call fmeparams. append ("fme_convert_to_area")
call fmeparams. append ("fme_drop_line")
set fmefeature = m_fmesession.createfeature
call m_fmefeaturevector.element (0 ). cloneattributes _
(fmefeature)
call fmefeature. processfeatures (m_fmefeaturevector, _
fmeparams)

Note: When processfeatures is called, the applicationProgramFmefeature itself will be deleted because it gives up all control over element vectors. If femfeare is will be used in the program later, the fmefeature will be copied (cloned) in depth before processfeatures is called ).

By default, unused line elements (F10 in this example) will also be returned to the result element array m_fmefeaturevector. If you do not want to return unused elements, you can give them to the store fme_drop_line in the fmeparams parameter list.

Note: If the application needs to process large datasets, use processfeaturesondisk instead of processfeatures. This method works in a disk-based object set. For more information about fmeofeaturevecw.disk, see Chapter 10th of this tutorial.

Integrated Polygon

By eliminating the public edges of adjacent polygon, the polygon is merged by using public attributes. It is very useful to merge polygon. For example, the fusion area is a sales area.

Processfeatures of fmeofeature provides a simple method to combine a polygon. Given a polygon, processfeatures are merged into a surface element, which can be a polygon, a ring, or a combination (including an Island ), merging polygon is a typical set-Based Element Processing.

For example, if the six polygon in Figure A are merged, Result B

 

M_fmefeaturevector contains a set of elements of the same attribute and element type. The following Code demonstrates how to use processfeatures to combine them and clone the first element in m_fmefeaturevector from the merged element attribute, the processing result is associated with a fmefeature.

 

Set fmeparams = m_fmesession.createstringarray
Call fmeparams. append ("fme_polygon_dissolve ")
Call fmeparams. append ("fme_drop_line ")
Set fmefeature = m_fmesession.createfeature
Call m_fmefeaturevector.element (0). cloneattributes _
(Fmefeature)
Call fmefeature. processfeatures (m_fmefeaturevector ,_
Fmeparams)

 

Tip: When processfeatures is called, the application loses control over the elements, and the fmefeature is deleted. If you want to use features later, clone the feature before processing.

 

The internal line element is returned to m_fmefeaturevector. If you do not want to return the internal line element, add fme_drop_line to the fmeparams parameter.

 

Buffer Elements

A buffer or simple buffer is a closed polygon with a certain distance from the point, line, and polygon. The buffer zone is very useful for near analysis. For example, it is used to find the forest area within the distance of 300 feet of the river, the buffer zone is a typical element-based geometric processing.

 

The buffer method of fmeofeature provides a simple method to create a buffer for an element. It replaces the geometric elements with a new surface element to represent the buffer. The following code creates a buffer for each element in m_fmefeaturevector and adds new elements to the set. The result is that m_fmefeaturevector contains the original elements and buffer elements, each of which is 0.1 units away from the original elements, sampling angle 5: The buffer element property is cloned from the original element.

 

Dim fmefeature as fmeofeature
Dim I as integer
Dim lcount as integer
Lcount = m_fmefeaturevector.entries
For I = 0 to lcount-1

Set fmefeature = m_fmesession.createfeature
Call m_fmefeaturevector.element (I). Clone (fmefeature)
Call fmefeature. buffer (0.1, 5)
Fmefeature. Attribute ("fme_type") = "fme_area"
Call m_fmefeaturevector.append (fmefeature)
Next I

The buffer function of fmeeofeature uses the @ buffer function.

Create an internal point for Deformation

To give a polygon element, your application generates the interior point of the polygon and uses the generatepointinpolygon method of fmeofeature to perform element-based geometric processing.

Next, create the internal points of each polygon element in the m_fmefeaturevector set and add them to m_fmefeaturevector. The result m_fmefeaturevector contains the original polygon element and the new vertex element. The Point property is cloned from the polygon.

dim fmefeature as fmeofeature
dim sfeaturetype as string
dim I as integer
dim lcount as integer
dim X as double
dim y as Double
dim Z as double
sfeaturetype = m_fmefeaturevector.element (0 ). featuretype
lcount = m_fmefeaturevector.entries
for I = 0 to lcount-1
set fmefeature = m_fmesession.createfeature
call m_fmefeaturevector.element (I ). _
generatepointinpolygon (false, x, y, z)
call fmefeature. addcoordinate (x, y, z)
fmefeature. featuretype = sfeaturetype
fmefeature. attribute ("fme_type") = "fme_point"
fmefeature. geometrytype = fopoint
call m_fmefeaturevector.append (fmefeature)
next I

The first parameter of generatepointinpolygon is a flag. If it is true, generatepointinpolygon searches for the center point for a long time. If it is a three-dimensional element, the Z value is also calculated.

 

Execute any function

FME functions provide flexible functions to operate elements. There are two types of functions: attribute functions are used to calculate attribute values, and element functions are used to operate elements. Geometric element attributes of element function operation elements. If your application requires FME functions, you need to read the FME functions chapter in the FME Foundation manual, FME functions, the Factories and transformers manual page is a useful reference.

 

The effecmfunction method of the fmeofeature object can run any function based on the element. For example, use the @ log element function to record one element:

Call fmefeature. Invoke mfunction ("@ log (data feature:,-1 )",_
Sresult)

Tip: If no parameter is specified when a function is called, mfunction reports an error.

When javasmfunction calls a feature function, the result parameter returns an empty string. When an attribute function is called, The result parameter returns the function output. For example, the following code adds a lot_area attribute to the element:

Call fmefeature. Invoke mfunction ("@ area (1000)", sresult)
Fmefeature. real32attribute ("lot_area") = sresult

 

Offset, rotation, and scaling Elements

The offset element is converted to a new position. The offset must be specified for X, Y, and Z (Optional). The Offset Method of the fmeofeature object is used for offset.

 

Another useful ry transformation is to rotate elements around a central point. The fmeofeature object uses rotate2d to rotate elements around the center counterclockwise.

 

You can also scale the elements by using the fmeofeature scale method.

 

Offset, rotation, and scaling are typical element-based geometric processing, such:

 

Call m_fmefeaturevector.element (I). offset (dxoffset ,_
Dyoffset, dzoffset)
Call m_fmefeaturevector.element (I). rotate2d (dxcenter ,_
Dycenter, dangle)
Call m_fmefeaturevector.element (I). Scale (dxfactor ,_
Dyfactor, dzfactor)

 

Operation aggregation Elements

The aggregate elements are introduced in chapter 3. The splitaggregate method of fmeofeature is used to break elements into non-aggregate elements and return a list containing these non-aggregate elements.

Note: This method does not clear the input elements, but only adds results.

 

There are two ways to create aggregation elements: chopup and buildaggresponfeature.

 

The chopup Method Based on Element Processing is used to add existing non-aggregate surface or line elements to aggregation. If the number of vectors of element ry exceeds a certain number, the excess part is not aggregated, the minimum aggregation threshold value is 10. For surface elements, the chopup decomposition surface is not a surface fragment. For line elements, the chopup method is called Based on the vector threshold value. Example:

Call m_fmefeaturevector.element (I). chopup (20)

The buildaggresponfeature method based on set processing creates an aggregate ry using the input geometric elements. The syntax is as follows:

Call fmefeature. buildaggresponfeature (m_fmefeaturevector)

Operating Environment Elements

The ring element is introduced in chapter 3. The getdonutparts method of fmeofeature returns the polygon ry that forms the ring element.

Note: This method does not clear the input elements and only adds them.

You can use the makedonuts method to create a ring element.

The makedonuts method constructs one or more ring elements from some polygon elements and returns a combination. This method is called as follows:

Call fmefeature. makedonuts (m_fmefeaturevector, false)

The second parameter of this method is the keepholes flag. If it is true, this method returns a polygon as the element Island.

The outershell method is used to obtain the outer ring polygon of the ring element. If the element that calls the outershell method is not a ring element, the method is called as follows:

Call fmefeature. outershell

If the format you process has a direction rule (left-hand or right-hand rule) on the coordinates of the components of the ring, you can use the getorientation and setorientation methods to control the sequence of coordinate storage.

Factory Pipeline)

The FME processor is a function that integrates elements and attribute values and is connected by the processor pipeline. The processor pipeline allows the FME object to execute element-based and set-based processing tasks. In fact, all the Element Processing described in this chapter uses the fmeofeature method, which can also be replaced by the element processor, replacing the built-in method with a processor pipeline requires some settings, but it is more powerful and easier to modify and expand.

If you want to use the processor pipeline, read the FME factories chapter in the FME Foundation manual, which provides some basic information about the FME processor, FME functions, factories and transformers.

The fmeopipelin object provides interfaces to construct and use a processor pipeline. The methods and attributes are as follows:

To use a processor pipeline, follow these steps:

    • Create and define Pipelines
    • Insert elements into the MPs queue
    • Retrieving elements from MPs queue

 

Create and define Pipelines

To create a new processor pipeline, you must use the createfactorypipeline method of the fmeosession object. The Code is as follows:

Set fmepipeline = m_fmesession.createfactorypipeline (_
"Test", fmedirectives)

 

The first parameter is the MPs queue name. The second parameter allows you to specify the processor and function parameters in the MPs queue. The keyword of the configuration parameter must be prefixed.

Note: The configurefunction method of fmeopipeline specifies the configuration for the function, such as @ lookup, @ relate, and @ SQL. parameters must be configured for these functions.

 

Once an MPS queue is created, three methods are available to specify the element processor:

    • Place all the processors into a text file and call the addfactories method.
    • Each independent processor is placed in a string and the addfactories method is called for each string.
    • Place each processor into the FME String Array and call addfactoryfromstringarray.

You can choose to use the method you think is appropriate to add a processor. First, all the processor pipelines will produce fewer errors during development and debugging in one file, pipeline files use the standard FME ing File Syntax (including connection characters). You can use the FME universal Viewer application pipeline to test the processor pipeline to an existing dataset (right-click the view node on the display control panel, apply pipleline command ).

 

Note: During the FME universal viewer test, if there are multiple datasets in the view, each dataset will be processed by a corresponding pipeline instance.

 

Once the pipeline function is designed, implemented, and tested, the addfactory and addfactoryfromstringarray methods can compile the Pipeline Code together with the program code to help protect your intellectual property rights, these two methods can also be installed in a file-based pipeline. The usage example is as follows:

Sfactory = "factory_def * donutholefactory"
Sfactory = sfactory & "input feature_type *"
Sfactory = sfactory & "fme_geometry fme_donut"
Sfactory = sfactory & "output outershell feature_type *"
Sfactory = sfactory & "output hole feature_type *"
Call fmepipeline. addfactory (sfactory ,"")

Note: When spaces are used as the delimiters of addfactory, function calls cannot contain spaces in the parameter list. If the processor contains attribute values that contain spaces, you will need to select other characters instead of spaces as the split width (in "|" or ";")

 

 

The following describes the addfactorys method.

 

Insert some elements to MPs queue

Once a processor pipeline is created and defined, it is ready to begin to accept elements and add elements to the processor pipeline. Your application must use the processfeature method of fmeopipeline:

Call fmepipeline. processfeature (_
M_fmefeaturevector.element (I ))

The processfeature method processes incoming elements and returns a null value. If the application wants to retain the original elements, use the fmeofeature clone method to copy them before processing.

Some elements returned from the MPs queue

Your application returns and processes elements through MPs queues, and the original elements entered are not changed by MPs queues.

If your MPs queue contains only one element-based processing processor, after processfeature returns control to the application, the results will be understood as available and getoutputfeature will be used to obtain the returned elements, for example:

Call fmepipeline. processfeature (_
M_fmefeaturevector.element (I ))
Bend = fmepipeline. getoutputfeature (fmefeature)

When the last element is read, getoutputfeature returns true.

When an MPS queue contains one or more collection-based processors, such as topologyfactory, polygonfactory, or sortingfactory, your application will use the alldone method of fmeopipeline to notify the MPs queue after the last element is inserted, after the alldone method returns control, the elements returned immediately become available. If getoutputfeature is called before alldone, elements cannot be read from the input. Although some elements may be in the pipeline, getoutputfeature returns true.

Note: An MTS queue cannot be reused after the alldone method is called. In other words, after alldone is called, The addfeature call fails.

Comprehensive Exercises

The following section describes how to use the file-based Processor pipeline to mark spipelinefile to process elements in m_fmefeaturevector.

Sub applypipeline (spipelinefile as string)
Dim I as integer
Dim lcount as integer
Dim bend as Boolean
Dim fmepipeline as fmeopipeline
Dim fmefeature as fmeofeature
Dim fmedirectives as fmeostringarray
Set fmepipeline = m_fmesession.createfactorypipeline (_
"Test", fmedirectives)
Call fmepipeline. addfactories (spipelinefile)
Lcount = m_fmefeaturevector.entries
For I = 0 to lcount-1
Call fmepipeline. processfeature (_
M_fmefeaturevector.element (I ))
Next I
Call fmepipeline. alldone
M_fmefeaturevector.clear
Bend = false
Do While bend = false
Set fmefeature = m_fmesession.createfeature
Bend = fmepipeline. getoutputfeature (fmefeature)
If bend = false then
Call m_fmefeaturevector.append (fmefeature)
End if
Loop
End sub

If you want to create a topology, you can use the above function to call the pipeline file. The pipeline file content is as follows:

Factory_def * polygonfactory \
Factory_name polygonbuilder \
Input feature_type *\
Fme_geometry fme_line \
FTYPE @ featuretype ()\
Group_by FTYPE \
Vertex_noded \
Output polygon feature_type *\
@ Featuretype (& FTYPE )\
@ Removeattributes (FTYPE )\
Fme_type fme_area

You can use the following pipeline file to fuse a polygon:

Factory_def * polygonfactory \
Factory_name polygonbuilder \
Input feature_type *\
Fme_geometry fme_line \
FTYPE @ featuretype ()\
Group_by FTYPE \
Vertex_noded \
Output polygon feature_type *\
@ Featuretype (& FTYPE )\
@ Removeattributes (FTYPE )\
Fme_type fme_area

As for the buffer elements and pipeline files that generate points inside the polygon, you can practice them yourself.

References:

Building applications with FME objects February 2005

reprinted please indicate Article source http://www.cnblogs.com/booolee

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.