Skip to main content
Question

Extract attribute value type from ESRI shapefile

  • September 29, 2020
  • 3 replies
  • 88 views

Hi there,

I'm trying to read attributes from a shapefile and write them into a SQL database. I need to write also the data type for every attribute, exactly as written in shape (not based on their values). How can I extract data types from data source?

Thank you for any help!

3 replies

jkr_wrk
Influencer
Forum|alt.badge.img+28
  • September 29, 2020

EXPAND THIS POST FOR MY UPDATE

 

I tested with an Postgris database and get following results:

 

id = long -> Int4

firsttext = char(80) -> varchar(80)

secondtext = char(200)-> varchar(200)

number = long -> Int4

other_numb = float -> Float4

date = date -> date

 

when connecting the schema to the writer and setting everything to dynamic. Removing all attributes from the User Attributes tab in the writer.

 

 

Guess that if you need more control you need to specify the Native Attribute Translation on the Schema Feature or specify the Schema manual.

 

 

Edit:

I did some more investigation and it looks like a shape file only knows 3 data types:

 

C for Character -> CHAR(x)

N for Numeric -> NUMERIC(x,y)

D for Date -> Date

 

But the reader gives native data types like short and long for these numeric data types. So i guess you need to read the DBF to figure out the real data types?

 

To write the correct data types to your SQL database you need to use the fme_char(x), fme_decimal(x,y) and fme_date as attribute_data_type. Where x and y are numbers.

 


david_r
Evangelist
  • September 29, 2020

If you read the data using the FeatureReader transformer, you'll get the datatypes from the <Schema> output port.

You'll find some details about the output here: https://community.safe.com/s/article/dynamic-workflow-tutorial-destination-schema-is-de-2


uvmsci
Participant
Forum|alt.badge.img
  • Participant
  • October 5, 2020
david_r wrote:

If you read the data using the FeatureReader transformer, you'll get the datatypes from the <Schema> output port.

You'll find some details about the output here: https://community.safe.com/s/article/dynamic-workflow-tutorial-destination-schema-is-de-2

Thank you very much david_r, that's exactly what I needed!


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings