From the course: FME Desktop: Data Translation for AEC

SHP to KML with Generate workspace

From the course: FME Desktop: Data Translation for AEC

Start my 1-month free trial

SHP to KML with Generate workspace

- [Instructor] The KML file is very useful for Google Earth or Google Maps. We're going to convert a shapefile into a KML format using the generate workspace inside of FME Workbench. So in a brand new session, I'm going to click generate workspace. And the first thing I'm going to choose is as Esri shapefile. If you don't see it in your dropdown list, you can always type more formats and do a search for shp, it should appear, I'll choose it there. Next we're going to browse to the dataset. Now, under the desktop, under exercise files, we're in two vector data with Workbench. We're going to pick on transit routes. These are the transit routes for the city where all the bus routes are. We're going to leave the coordinate system alone, it'll read it from the PRJ file. The format, we're going to write to is KML. If it's not in your list, again, go more formats and type K-M-L, and it should appear in the writer gallery. Pick on that and click OK. We have an Esri shapefile looking at the transit route shape. And for the writer we have Google KML. We're going to put this directly to the desktop. So I'm going to browse the desktop. Just go up, exercise, desktop. There we are. And I'm just going to call this transit, transit.KML. That's what it's going to be. Now I have an option to put KMZ or KMZ and that sort of a compressed version of KML, but by default, it'll be .KML, and we're going to leave static schema. The difference between static and dynamic is static is a one-to-one. So you'll get a new file for every type. So for example, if you have line work, that'll be its own file. You have points, that'll be its own file. All the attributes will be broken out into the proper type, depending on the feature type it is. Whereas the dynamic, it could be all squished together. And what happens is FMI will figure out what sort of data types should be put into each category, as well as if your attributes change. That's very useful. Normally I use static schema, but for long-term projects, I use dynamic, especially when you know that field names may change within your project or the structure of the data may change just that it's dynamic, but let's leave static for now and we'll click OK. Now I'm just going to zoom out so we can see everything. There we go. And I'm going to drag the writer over so we can see that. So now we have transit routes going to transit routes, and I'll just zoom in a little bit. There we go. And if I expand the transit routes here, you select, you can see that inside the shapefile is the FID a route, a description and shape length. And inside the writer, we've got all the KML IDs and that sort of thing, as well as the columns. Now I may want to change the description to a proper description. So I'll just double-click on that and under user attributes where you see description under user attributes, I'm just going to put the n in there and I may actually change len to length, like that. So just little easier to read, but look what happens, the description is now yellow and the shape link is now yellow. So we have to match description, description. So I'm going to drag the little yellow arrow over to description and the shape underscore len is going to go to shape underscore length. So I'm going to drag that over. And there we go. Now all four columns are green because they're going to their corresponding column on the other side, inside the KML. So this is the KML side on the writer and the reader's shapefile. You can, if you ever curious of what your reader, writers are, just go to your navigator and you could see that in the navigator it says a shapefiles, the transit routes and transit is OGCKML. That's the open geospatial consortium, okay. The next thing we're going to do is we're just going to click run, and create the KML file. There we are. It's just checking the source parameters, yes. It's going from the desktop, perfect. And you can see down in the translation lock what's happening. And it says all 38 features are out with about seven warnings. You could scroll up to see any warnings that we have. And it's a few warnings up here. Basically, some of the things you can get set. So there we are. There's nine warnings. You can see all the information down below. You can toggle them on and off. So we have zero errors, nine warnings, and a little bit of information. There we are. You could toggle the word wrap. So it'll wrap around. So it's easier to read, to remove the line numbers or search for a particular issue or modify your log options at the bottom. But right now we're happy because we translated all 38 features out. So let's look at that. So what we're going to do, we're going to go to our desktop and look at the transit KML. I'm going to right click and I'm going to open it. Now because I have Google Earth installed, it'll automatically open that KML in Google Earth. I'm going to hit close and you can see it'll zoom into where we are, where the transit routes are. And there they are. There's all the transit routes. I'll turn off all the places. There we go. So let's zoom in and pick on one of these lines and sure enough, there's route one with the FID 30. And there's the description. It's the center line for bus route one. And there's the shape length. Remember we changed the word description and shaped length. So it's a little more descriptive. There we are. But you know it's coming in as white, let's change it to red. So let's go back to FMI and we're going to use KML specific transformer. So with my mouse just in this area, underneath where all the reader and writers are, I'm going to just start typing K-M-L, in the middle of nowhere. And sure enough, I get all sorts of things like KML property center, region center, time center, all sorts of things. I could also do this by going under the transformers, add transformer and search for one like that with KML. I can add transformer anytime just by clicking and typing in the middle of nowhere. So again, I can click in here KML and sure enough. So what I want to do is use the KML styler. That's the one I'm really interested. So I'll just pick on that. And there it is. It's not docked to anything, you could see it's red here. Nothing's connected. So what I'm going to do is I'm going to drag that up and put it exactly where that number 38 is. That's how many features were translated last time. But what we're going to do is that's the connector between the shape file and the KML. So what I do is I drag up and then when the connector turns green, I let go. And sure enough, now it's connected. Now you'll notice that the KML styler is in between the reader and the writer. Now, if I just double click on KML styler, what I'm going to do is I'm going to change the color. Since there lines, I don't have to worry about fill or fill a pass or anything like that. I just want colors. So I can hit browse and pick say red, so on all my routes to be red. So if I click OK, and okay you'll see it's reds they're 170. And now if I run this again, okay, 38, you see 38 went into the styler and 38 came out as a styler. Let's go back to Google Earth and add that file again. So on my desktop transit.KML, now let's remove the one that was there before. And there you go. So I just deleted the one I already had in my map because it was obscuring the new red one. So now I only have one transit routes and there they are, they're red. Using the generate workspace. We can convert the shape file into KML very quickly. And with a tiny little bit of work with a transformer, we can change the color of that KML. And then you could see that KML inside of Google Earth.

Contents